WHAT I HAVE
I am using Firebase Authentication in my app where the users can register using Email & Password. If the users have not verified their email, I disable some features until they verify their email.
I also have a button to explicitly trigger verification mail, which just calls, sendEmailVerification()
. It works perfectly and verification mail is always sent.
THE PROBLEM
The user gets the verification mails, but when he/she verifies it and comes back to the app, the isEmailVerified()
is always false. So my app still doesn't allow the user to use all functions in spite of the fact that he/she has verified their email.
But if they log out and login again, the isEmailVerified()
returns true immediately. But is it not good to log out the user and login back again.
Is it a bug in Firebase? Or am I doing something wrong?
Enable Email Link sign-in for your Firebase projectOn the Sign in method tab, enable the Email/Password provider. Note that email/password sign-in must be enabled to use email link sign-in. In the same section, enable Email link (passwordless sign-in) sign-in method. Click Save.
To customize your Firebase project's email action handler, you must create and host a web page that uses the Firebase JavaScript SDK to verify the request's validity and complete the request. Then, you must customize your Firebase project's email templates to link to your custom action handler.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
Hey I know that this is a pretty old thread, but what solved the problem for me FIRAuth.auth()?.currentUser.reload(completion: { (error) in ... })
For anyone that is facing this problem. And I am using the latest Firebase version 10.0.1
Firebase has changed the names of their functions since I've posted my solution.
Please note that all of changes to the current user states can be observed by adding an stateDidChangeListener. Auth.auth()?.currentUser is not updated immediately, so what I did was save the current user to a global variable I created and maintained myself.
Auth.auth().addStateDidChangeListener { (auth, user) in // ... }
Whenever you call Auth.auth()?.currentUser.reload()
a refreshed and ready to use user object will be passed through the stateDidChangeListener.
You can then check for any updated data(i.e emailVerified)
Here's how I solved this using react-native:
const user = firebase.auth().currentUser; user.reload().then(() => { console.log({emailVerified: user.emailVerified}) })
I coupled this with AppState to run the reload if user is bringing the app from the background to the foreground.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With