Flutter: How to listen to the FirebaseUser is Email verified boolean?

后端 未结 8 741
走了就别回头了
走了就别回头了 2021-01-01 20:38

My Idea: I want to use the Firebase Auth Plugin in Flutter to register the users. But before they can access the App, they have to verify their Email addres

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 21:06

    Since authOnChanged only listens for sign in and sign out actions, in your sign in method, first sign out then try to sign in.

    await _firebaseAuth.signOut();
    
    authResult = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
    
    return authResult.user;
    

    In the onAuthChanged, when you control if user.isEmailVerified, it will work since you have signed out and it will update the user even if you haven't signed in yet because sign out will trigger your onAuthChanged even if you haven't signed in.

    It is like cheating but the only way that I have found without timeout is this.

提交回复
热议问题