-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Bug report
Describe the bug
There is an emailVerified property of the currently logged in user that can be accessed by using:
FirebaseAuth.instance.currentUser.emailVerified
I would like to listen to changes to this emailVerified property, so I've tried to listen the following streams:
FirebaseAuth.instance.userChanges(). Which mentions: "This is a superset of both [authStateChanges] and [idTokenChanges]."FirebaseAuth.instance.authStateChanges()FirebaseAuth.instance.idTokenChanges()
These streams have been used in conjunction with the StreamBuilder widget.
When the user goes to verify their email by using the verification link that was sent to their inbox, none of these streams get notified of this state change (of emailVerified).
The workaround that I have been applying is setting up a periodic timer that calls FirebaseAuth.instance.currentUser.reload(); every 10 seconds. I went for 10 seconds since that was sufficient enough in my use case. By calling FirebaseAuth.instance.currentUser.reload() periodically, the FirebaseAuth.instance.userChanges() gets triggered soon after (within 10 seconds) the user has verified their email.
Steps to reproduce
Steps to reproduce the behavior:
- Sign into your app with FirebaseAuth, preferable with an email account so that we can verify the email later.
- Set up a stream listener to
FirebaseAuth.instance.userChanges() - Set up a breakpoint or print within the listener to be aware of when the stream gets triggered
- Change the
emailVerifiedstatus in Firebase Auth by either using forgot password or email verification link - Observe the stream, it should get triggered with new data but it does not.
Expected behavior
The expected behavior would be that FirebaseAuth.instance.userChanges() gets triggered and that the returned value of the stream contains the latest state of the user. The issue here is that the stream does not get triggered at all.
Sample project
No sample project prepared since this requires to be setup with an active Firebase project, I have not done so.
Additional context
This problem is not unique to Firebase Auth for Flutter, since this issue persists with Firebase Auth for JavaScript as well. A small difference with JavaScript is that their Firebase Auth SDK does not have this a similar (superset) stream:
FirebaseAuth.instance.userChanges()
But it does have the following streams taken from the Firebase Auth for JavaScript docs:
- [onIdTokenChanged] https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#onidtokenchanged
- [onAuthStateChanged] https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#onauthstatechanged
Both of these streams do not get triggered when the emailVerified of the currently logged in user changes.
Flutter doctor
Run flutter doctor and paste the output below:
Click To Expand
PASTE OUTPUT INSIDE HERE
Flutter dependencies
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
PASTE OUTPUT INSIDE HERE