flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [flutterfire_ui] Auth: Profile screen does not rebuild after email verification status changes.

Open neiljaywarner opened this issue 2 years ago • 6 comments

Email auth has a "waiting for email" with a spinner on the profile screen.

Expected behaviour:

  1. background app
  2. go to emamil, click on verify, observe success message, background email
  3. Return to app from recents menu
  4. Observe waiting and profile vanish

Actual behaviour: Signing out and signing back in causes it to vanish. Note: I'm on flutter UI flutterfire_ui: 0.4.0+5 because 0.4.1 seems to require flutter 3.

neiljaywarner avatar May 13 '22 22:05 neiljaywarner

@neiljaywarner Is this happening on Android or iOS ? Does the same behavior occur using plugin's example too ?

darshankawar avatar May 16 '22 10:05 darshankawar

Plugins example required many files but authgate code cones from docs.

I didn't try ios

....sent from my phone

On Mon, May 16, 2022, 5:39 AM darshankawar @.***> wrote:

@neiljaywarner https://github.com/neiljaywarner Is this happening on Android or iOS ? Does the same behavior occur using plugin's example too ?

— Reply to this email directly, view it on GitHub https://github.com/firebase/flutterfire/issues/8683#issuecomment-1127507940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXBGYKJNKIXCHNRKQJN7CLVKIQWFANCNFSM5V4UWZBA . You are receiving this because you were mentioned.Message ID: @.***>

neiljaywarner avatar May 16 '22 15:05 neiljaywarner

I've made this "Waiting for email verification" screen myself. I discovered that this is an issue with Firebase Auth, the FirebaseAuth.instance.authStateChanges() stream does not fire when the emailVerified flag gets changed on your Firebase Auth profile. Nor does it fire by using FirebaseAuth.instance.userChanges() and even FirebaseAuth.instance.idTokenChanges(). None of the FirebaseAuth streams get fired when the emailVerified flag gets changed.

My solution was to create a looping timer (e.g. every 10 seconds) and call "FirebaseAuth.instance.currentUser?.reload();".

Here's an example: @override void initState() { super.initState(); _timer = Timer.periodic(const Duration(seconds: 10), (timer) { FirebaseAuth.instance.currentUser?.reload(); }); }

Make sure you define Timer _timer in your statefulwidget and don't forget to cancel the timer when the e-mail has been verified.

By forcing the ...currentUser?.reload() method, the FirebaseAuth.instance.userChanges() stream will get triggered and the User object you get back from that stream will have an up-to-date emailVerified boolean. E.g. this will work: user?.emailVerified == true.

BrutalCoding avatar May 17 '22 00:05 BrutalCoding

@BrutalCoding Thanks for the update. Can you open a new issue mentioning all these details so that we can track and address it properly and possibly link this issue to it as a reference, because per your comment / findings, the issue probably lies in firebase_auth and may not be specific to flutterfire_ui plugin since it seems to leverage the auth implementation.

darshankawar avatar May 17 '22 10:05 darshankawar

I also agree with this issue. You should be able to check the emailVerified status with reload() .

Patrick386 avatar May 18 '22 10:05 Patrick386

@BrutalCoding Thanks for the update. Can you open a new issue mentioning all these details so that we can track and address it properly and possibly link this issue to it as a reference, because per your comment / findings, the issue probably lies in firebase_auth and may not be specific to flutterfire_ui plugin since it seems to leverage the auth implementation.

Thanks for the suggestion, I have opened a new issue here https://github.com/firebase/flutterfire/issues/8777 and described it in more detail.

I personally think that its not only Flutter's firebase_auth package that is affected by this, but it might be a widespread issue with all Firebase Auth SDK's. The reason I say this is because Firebase Auth for JavaScript faces the same issue: https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#onauthstatechanged

BrutalCoding avatar May 26 '22 06:05 BrutalCoding

I wanted to bring some attention to more issues related to the ProfileScreen not rebuilding with #9682. Maybe it is related.

guplem avatar Oct 06 '22 08:10 guplem

fixed in #9343

lesnitsky avatar Oct 17 '22 14:10 lesnitsky