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

后端 未结 8 679
走了就别回头了
走了就别回头了 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:32

    This verification isn't as straightforward as you'd hope. First, there is the problem of recognizing that the user has verified their email. Second, there is the issue that there isn't any sort of a notification you can listen to that will automatically trigger a change in your app.

    Check this thread for info about emailVerified: https://github.com/flutter/flutter/issues/20390#issuecomment-514411392

    I was only able to verify the user if I 1) Created their account, 2) Signed them in, 3) Then checked to make sure they verified their email.

    final FirebaseAuth _auth = FirebaseAuth.instance;
    
    var _authenticatedUser = await _auth.signInWithEmailAndPassword(email: _email, password: _password); 
    
    //where _email and _password were simply what the user typed in the textfields.
    
    
    
    if (_authenticatedUser.isEmailVerified) {
            //Verified
          } else {
            //Not verified
            }
    

    Part 2: How do you get your app to recognize that the user has confirmed their email? Find a way to trigger the function that checks confirmation. A button would be easy enough. If you want it to see "automatic" then I guess you could create a timer that checks for email verification every 10 seconds or so.

提交回复
热议问题