smf_firebase_auth 0.5.0 copy "smf_firebase_auth: ^0.5.0" to clipboard
smf_firebase_auth: ^0.5.0 copied to clipboard

The SMF module of Firebase Authentication for the Flutter app that SMF generates. The users of the app sign in with an email address and a password, or as anonymous users.

example/README.md

Generate a Flutter app that signs in with Firebase Authentication #

firebase_auth is the module of the SMF CLI with which the users of the app sign in through Firebase Authentication. Choose it with -m in a terminal:

dart pub global activate smf_flutter_cli
smf create my_app -m firebase_auth

It depends on firebase_core, which sets up Firebase, so smf create adds that module too:

Adding firebase_core: a dependency of firebase_auth.
Adding flutter_core: the only provider of the app entry role, which every app needs.

The module adds firebase_auth to the pubspec.yaml of the app, and lib/core/auth/firebase_auth_service.dart with the sign-in service on FirebaseAuth.instance. The auth role adds lib/core/auth/app_session.dart with appSession, which the rest of the app uses. bootstrap() starts Firebase and then the session, so the app knows who is signed in before its first frame:

Future<void> bootstrap() async {
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await initAuth();
}

The code of the app signs in, up and out through appSession, and shows a text of its own for the reason of a failure:

import 'core/auth/app_session.dart';

Future<String?> signIn(String email, String password) async {
  try {
    await appSession.signIn(email: email, password: password);
    return null;
  } on AuthFailure catch (failure) {
    return switch (failure.reason) {
      AuthFailureReason.invalidCredentials => 'Wrong email or password.',
      AuthFailureReason.network => 'No connection. Try again.',
      _ => 'Sign-in is unavailable.',
    };
  }
}

appSession.value is a SignedOutSession, an AnonymousSession or an AccountSession, and a widget follows it with a ValueListenableBuilder.

smf create asks who may use the app without an account, or takes the answer from --auth-mode: required, the default, guest or anonymous. In the mode anonymous, the app signs in an anonymous user when it starts, and signing up gives that user the account.

The ways to sign in are enabled in the Firebase project: Email/Password, and Anonymous for the mode anonymous. In a terminal, smf create offers to enable them right after flutterfire configure configured the app. To enable them later, run in the directory of the app:

dart tool/enable_firebase_sign_in.dart

The script enables them with the Firebase CLI, which adds a web app named "Default Web App" to a project that has no web app. The Firebase console enables them without it, and the README of the app tells where. Until they are enabled, a call fails with the reason notConfigured, and its developerHint tells how to enable them.

The documentation has more on the firebase_auth module and on Firebase.

0
likes
160
points
--
downloads

Documentation

Documentation
API reference

Publisher

verified publishersaymyframe.com

Weekly Downloads

The SMF module of Firebase Authentication for the Flutter app that SMF generates. The users of the app sign in with an email address and a password, or as anonymous users.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#flutter #firebase #authentication #sign-in

License

Apache-2.0 (license)

Dependencies

mason, smf_contracts, smf_firebase_core

More

Packages that depend on smf_firebase_auth