0
votes

There isn'y enough documentation on this subject. so I'm looking for some experiences from amazing people out here.

We need the main sign in method in the app to be using phone number as user name and user chosen password, Phone will be verified with OTP upon registration and when resetting password.

Flutter offers sign in using phone verification, as far as I know each time user has to go through OTP. I need the user to set a password and only verify phone once at signup or when resetting password.

also we wanna link the credentials to a firestore user profile (name, job, email, etc). How would we do that?

Code for sign in using email:

CustomMaterialButton(
  onPressed: () async {
    try {
      final UserCredential _userCredential =
          await _firebaseAuth.signInWithEmailAndPassword(email: _user.email, password: _user); //_user is a custom made class that has user profile data
      if (_userCredential != null) Navigator.pushNamed(context, HomeScreen.screenId);
    } catch (e) {
      showCustomSnackBar(context, e.message);
    }
  },
  text: "Log in"),

code for sign up:

CustomMaterialButton(
  onPressed: () async {
    try {
      final UserCredential _newUserCredential =
          await _firebaseAuth.createUserWithEmailAndPassword(email: _user.email, password: _user.password);
      if (_newUserCredential != null) {
        Navigator.pushNamed(context, VerifyPhoneScreen.screenId);
      }
    } catch (e) {
      showCustomSnackBar(context, e.message);
    }
  },
  text: "New user signup"),

Screen 1

Screen 2

Screen 3

1

1 Answers

0
votes

Once a user is signed in to Firebase Authentication (whether with phone number or another method of signing in) they stay signed in, unless you either explicitly sign them out, or a compelling event (such as changing their password, disabling their account) happens.

As long as you listen to auth state changes, the app should reflect the user's sign-in state. If you're having trouble making this work in your app, edit your question to show that you tried.