An AuthProvider interface with FirebaseAuth implementation

Usage


final AuthProvider authProvider = FirebaseAuthProvider();
authProvider.signOut();

final signInResult = authProvider.emailPasswordSignIn(
    LoginCredentials("some@email.com", "secretPassword"));

final AuthUser currentUser = authProvider.currentAuthUser;
print("Currently logged in as: ${currentUser.displayName}, ${currentUser.email}, ${currentUser.id}");

authProvider.authUserChanged.listen((authUser) {
    print("Auth user changed");
    print("Is logged in: ${authUser.isLoggedIn}");
    if (authUser.isLoggedIn) {
    print("Currently logged in as: ${currentUser.displayName}, ${currentUser.email}, ${currentUser.id}");
    }
});

Use the AuthStateWrapper to handle listening to the current auth state and display the correct page accordingly.


final AuthStateWrapper authStateWrapper = AuthStateWrapper(
    authProvider: authProvider,
    signedIn: (context) => HomePage(),
    notSignedIn: (context) => LoginPage(),
    loading: (context) => const CircularProgressIndicator(),
    error: (context, error) => Text("Error occurred: $error"));

Libraries

firebase_auth_helper
main