Firebase UI for authentication provides a simple and easy way to implement authentication in your Flutter app. The library provides fully featured UI screens to drop into new or existing applications, along with lower level abstractions for developers looking for tighter control.
Activate FlutterFire CLI
dart pub global activate flutterfire_cli
Install dependencies
flutter pub add firebase_core
flutter pub add firebase_auth
# required for email link sign in and email verification
flutter pub add firebase_dynamic_links
flutter pub add firebase_ui_auth
Configure firebase using cli:
flutterfire configure
Initialize firebase app:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
If you're building for macOS, make sure to add necessary entitlements. Learn more from the official Flutter documentation.
If you're writing widget unit tests, you'll need to add the following to your setUpAll
method:
setUpAll(() {
setFirebaseUiIsTestMode(true);
});
Also, you will likely want to mock the FirebaseAuth
instance:
class MockFirebaseAuth extends Mock implements FirebaseAuth {
/// mock necessary methods
}
An instance of MockFirebaseAuth
can then be passed to Firebase UI widgets:
SignInScreen(
auth: MockFirebaseAuth(),
/// ... other props
)
To understand what Firebase UI for authentication offers, the following documentation pages walk you through the various topics on how to use the package within your Flutter app.
-
Available auth providers:
- EmailAuthProvider - allows registering and signing in using email and password.
- EmailLinkAuthProvider - allows registering and signing in using a link sent to email.
- PhoneAuthProvider - allows registering and signing in using a phone number
- UniversalEmailSignInProvider - gets all connected auth providers for a given email.
- OAuth