सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
lit_firebase_auth एक Flutter पैकेज है जो Firebase Authentication के एकीकरण को सरल बनाता है, जिसमें पूर्व-निर्मित UI घटक और सुविधाजनक सेटअप शामिल है। त्वरित कार्यान्वयन के लिए डिज़ाइन किया गया, यह विकासकर्मियों को अपने ऐप में सुरक्षित प्रमाणीकरण प्रवाह—जैसे लॉगिन, रजिस्टर और पासवर्ड पुनर्प्राप्ति—को मिनटों में जोड़ने में सक्षम बनाता है। पैकेज जटिल Firebase Auth तर्क को छुपाता है, बॉयलरप्लेट कोड को कम करता है जबकि लचीलापन बनाए रखता है। यह ईमेल/पासवर्ड, Google और Apple Sign-In जैसे सामान्य प्रमाणीकरण विधियों का समर्थन करता है, जिससे यह गति और विकासकर्मी अनुभव पर ध्यान केंद्रित करने वाले परियोजनाओं के लिए आदर्श है बिना सुरक्षा के त्याग के।
उपयोग
नए Flutter ऐप्स में Firebase Auth को तेजी से जोड़ें
न्यूनतम कोड के साथ ईमेल/पासवर्ड लॉगिन का कार्यान्वयन
सोशल लॉगिन (Google, Apple) सक्षम करें
निर्मित यूआई घटकों के साथ प्रमाणीकरण प्रवाह बनाएं
प्रमाणीकरण विशेषताओं के सेटअप समय को कम करना
मुख्य विशेषताएँ
पूर्व-निर्मित प्रमाणीकरण यूआई स्मार्टविजेट
आवश्यक न्यूनतम कॉन्फ़िगरेशन
कई लॉगिन विधियों का समर्थन करता है
Firebase के साथ निरंतर एकीकरण
साफ, पुन: उपयोग करने योग्य प्रमाणीकरण घटक
इनके लिए उपयुक्त
शुरुआती से मध्यम स्तर के Flutter विकासकर्ता
त्वरित प्रमाणीकरण के आवश्यकता वाले प्रोजेक्ट
Firebase का बैकएंड के रूप में उपयोग करने वाले ऐप्स
प्रोटोटाइप और एमवीपी
त्वरित विकास पर केंद्रित टीमें
विचार योग्य बातें
हाथ से सेटअप की तुलना में सीमित कस्टमाइज़ेशन
Firebase सेवाओं पर निर्भर करता है
अतिरिक्त अवस्था प्रबंधन की आवश्यकता हो सकती है
अत्यधिक विशेषज्ञता वाले प्रमाणीकरण कार्य प्रवाह के लिए उपयुक्त नहीं
बाहरी GitHub भंडार पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Lit Firebase Auth
⚠️ Attention: This package is at an early stage. A lot of features are missing. Eventually this package will be "lit", but for now, use at your own risk.
Pre-lit Firebase authentication. It provides a set of convenient utilities and widgets to easily add Firebase authentication to a Flutter app.
Easily interact with Firebase from anywhere in your app
Monitor the auth state and react to changes
Error handling and error messages
Built in error handling that will display friendly in-app error messages
Error/Success dialogs can be customized
Highly customizable
Either use the standard sign-in widgets, or create your own.
Getting started
Please note that before this package can be used, Firebase Core needs to be initialized in your application. See the official FlutterFire documentation for up to date information.
For a complete example (with Firebase initialization) see the example project.
Note that this video was recorded with the old version of FlutterFire and Lit Firebase Auth. As such, some configuration may be different. For example, this does not show how to initialize FlutterFire.
Below is an example of a Flutter Web index.html with Firebase Auth enabled:
...
<body><!-- GOOGLE SignIn Client ID --><metaname="google-signin-client_id"content="ADD-YOUR-CLIENT-ID.apps.googleusercontent.com"><!-- The core Firebase JS SDK is always required and must be listed first --><scriptsrc="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script><scriptsrc="https://www.gstatic.com/firebasejs/7.15.5/firebase-auth.js"></script><!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries --><script>// Your web app's Firebase configurationvar firebaseConfig = {
...// ADD CONFIG HERE
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script><!-- CONTINUE TO INITIALIZE FLUTTER WEB -->
...
Usage
The two most important widgets are
LitAuthInit - which initializes the package and exposes the services that will be used in your application.
LitAuth - which renders the UI (forms, buttons and dialogs).
Lit Firebase Initialization
First, you need to initialize the package with LitAuthInit. This should be at the root of your application. Above MaterialApp/CupertinoApp, and above any widgets that want to access authentication functionality.
For example:
classMyAppextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
// Needs to be above [MaterialApp]/[CupertinoApp]returnLitAuthInit(
// specify which auth providers to enable
authProviders: AuthProviders(
emailAndPassword: true, // enabled by default
google: true,
apple: true,
twitter: true,
github: true,
anonymous: true,
),
child: MaterialApp(
title: 'Material App',
home: Home(),
),
);
}
}
Standard Sign-in widget
You can either create your own custom sign-in widget, or make use of the standard built in one.
To use the standard sign-in form with no changes:
LitAuth();
This will use the default configuration and UI theming.
The majority of the configuration is on Firebase side. First, Google Sign In needs to be enabled in the Authentication section of your Firebase project. Next, if you have not done so yet, you will need to provide your application's SHA certificate within your Firebase settings and replace the google-services.json file with the updated one. This is needed for Google Sign in to be allowed.
A correctly setup Firebase project and the correct google-services.json file is all you'll need.
Google Sign In for iOS
Lit Firebase Auth uses the google_sign_in package for Google Sign in. Please see their documentation if you encounter difficulties.
Please ensure you have done the steps outline in iOS integration
Then add the CFBundleURLTypes attributes below into the [my_project]/ios/Runner/Info.plist file.
<!-- Put me in the [my_project]/ios/Runner/Info.plist file --><!-- Google Sign-in Section --><key>CFBundleURLTypes</key><array><dict><key>CFBundleTypeRole</key><string>Editor</string><key>CFBundleURLSchemes</key><array><!-- TODO Replace this value: --><!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID --><string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string></array></dict></array><!-- End of the Google Sign-in Section -->
iOS additional requirement
Note that according to https://developer.apple.com/sign-in-with-apple/get-started,
starting June 30, 2020, apps that use login services must also offer a "Sign in
with Apple" option when submitting to the Apple App Store.
Google Sign in for Web
You will need to add the Google Sign in Client ID to your index.html file. You can get this ID from the Firebase console, within the Google Sign-in Web Configuration (Authentication section).
An example is below:
web/index.html
...
<body><!-- GOOGLE SignIn Client ID --><metaname="google-signin-client_id"content="ADD-YOUR-CLIENT-ID.apps.googleusercontent.com">
...
Apple Sign In for Android
This should be working, but has not been tested. There should be configuration examples in the Firebase documentation.
Other identity providers (for example, Facebook) will need to be implemented separately. After successful third party sign in you can sign in to Firebase by making use of the signInWithCredential method available on BuildContext.
For example:
Widgetbuild(BuildContext context) {
AuthCredential credential = // get credential for identity provider (Facebook, etc.)
context.signInWithCredential(credential);
}
Decoration and theming
The UI can be as customizable as you need. But for simple usage it's fairly straight forward.
It's easy to provide custom decoration/configuration for the sign-in elements. You can either customize the elements of the standard sign-in widget, or create an entirely custom sign-in widget from scratch. Up to you.
Standard Sign-in widget customization
For example, to override the standard email TextFormField just provide a TextFieldConfig for the emailTextField parameter. In this example we are providing a new [style] and [inputDecoration]:
classYourCustomSignInWidgetextendsStatelessWidget{
constCustomSignInWidget({Key key}) : super(key: key);
@overrideWidgetbuild(BuildContext context) {
returnColumn(
children: [
Text('Welcome', style: Theme.of(context).textTheme.headline4),
// You need to wrap the custom sign-in widgets with a SignInForm.// This is used to validate the email and passwordSignInForm(
formChild: Column(
children: [
Padding(
padding: constEdgeInsets.all(8.0),
child: Text(
'A custom form',
style: Theme.of(context).textTheme.headline5,
),
),
Padding(
padding: constEdgeInsets.all(8.0),
child: EmailTextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(labelText: 'My Email Label'),
),
),
Padding(
padding: constEdgeInsets.all(8.0),
child: PasswordTextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(labelText: 'My Password Label'),
),
),
RaisedButton(
onPressed: () {
context.signInWithEmailAndPassword();
},
child: Text('Sign In'),
),
FlatButton(
onPressed: () {
context.signInAnonymously();
},
child: Text('Anony Sign In'),
),
],
),
),
],
);
}
}
NOTE: SignInForm needs to be provided above the EmailTextFormField and PasswordTextFormField.
The state of the password and email can be cleared manually by calling:
context.resetSignInForm()
This will reset the form to its initial state.
It's a good idea to do this when you have multiple EmailTextFormField and PasswordTextFormField widgets in separate locations, for example when you have a separate Sign-in form and a Registration form.
Icons
It's possible to use the OAuth icons provided by the package. For example: