When a user signs up they are forced to verify their email. This works but I want the user to be automatically led to the next page if they successfully verify their email. I implemented a StreamBuilder with the userChanges() function.
@override
Widget build(BuildContext context){
return StreamBuilder<User?>(
stream: FirebaseAuth.instance.userChanges(),
builder: (BuildContext context, AsyncSnapshot<User?> snapshot){
if(snapshot.data == null){
return const SignupPage();
}else
if(snapshot.data!.emailVerified){
return const HomePage();
}
return const WaitingText();
},
);
}
Now when the user verifies their mail the page doesn't get updated, but when I force a reload with currenUser.reload() it works. Is a StreamBuilder the way to go here? I don't want to constantly reload my user until they verify.
CodePudding user response:
This sounds like the expected behavior: the userChanges()
stream fires an event when any property of the user changes, but there is no immediate propagation of the server-side change to the client.
This means the verification is only picked up in your client when you re-authenticate the user (i.e. sign-out and sign in again) or when you force the SDK to reload the user profile.