I am new to flutter web, how to authenticate users using firebase phone authentication, is there a way to keep user logged in?

298

Users automatically stay signed in to Firebase. To pick up the user's authentication state when the app is restarted, check the documentation on authentication state, which has this handy example:

FirebaseAuth.instance
  .authStateChanges()
  .listen((User user) {
    if (user == null) {
      print('User is currently signed out!');
    } else {
      print('User is signed in!');
    }
  });

Also see the answer I just gave to: Anonymous User not detecting by firebase code error

Share:
298
Sai
Author by

Sai

Updated on December 27, 2022

Comments

  • Sai
    Sai over 1 year

    Here's a basic code for sign-in using firebase phone authentication, which can be understood from basic flutter-fire documentation, which doesn't explain practically how to implement firebase phone authentication in flutter web. Flutter Native mobile phone authentication is easy :)

    Also, how to remember the signed user for certain days?

    FirebaseAuth auth = FirebaseAuth.instance;
    
    ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber('+44 7123 123 456');
    
    UserCredential userCredential = await confirmationResult.confirm('123456');
    
  • Sai
    Sai about 3 years
    Hey Frank, do I need to use firebase_auth or firebase_auth_web package for the web app?