在电子邮件中验证邮件时,不会调用onAuthStateChanged [英] onAuthStateChanged doesn't get called when email is verified in flutter
问题描述
当用户注册我的应用程序时,他会收到一封验证电子邮件.当使用createUserWithEmailAndPassword
创建用户时,会调用onAuthStateChanged
-listener,但在验证电子邮件后不会调用.
When a user signs up in my app he gets a verification e-mail. The onAuthStateChanged
-listener gets called when a user gets created using createUserWithEmailAndPassword
but not after the email got verified.
我有一个单独的类来处理所有身份验证.以下方法是注册用户
I have a separate class which handles all authentications. The following method is to sign up user
Future<FirebaseUser> signUpUser(email, password) async {
final FirebaseUser user = await _auth.createUserWithEmailAndPassword(email: email, password: password);
assert (user != null);
assert (await user.getIdToken() != null);
return user;
}
使用此方法在我的StatefulWidget中调用此方法
This method is called in my StatefulWidget using this method
void _signUpUser() async {
try {
await Auth().signUpUser(_email, _password)
..sendEmailVerification();
} catch (e) {
print(e.toString());
}
}
在我的StatefulWidget
FirebaseAuth.instance.onAuthStateChanged.listen((user) {
print("Auth State Changed!");
if (user.isEmailVerified) {
print("EMail verified!");
}
}
推荐答案
onAuthStatechanged
仅在用户登录或注销时触发.不在电子邮件验证上.
onAuthStatechanged
is triggered only in case of user Login or Logout & not on Email verification.
按照文档-
onAuthStatechanged
为更改用户登录状态添加观察者.
onAuthStatechanged
Adds an observer for changes to the user's sign-in state.
观察者将在以下情况下触发:
The observer will be triggered in the following scenarios:
首次调用auth().onAuthStateChanged()时.它将触发 初始的Auth状态.如果用户正在从 auth().signInWithRedirect()操作,观察者将等待 在最初触发之前解决的操作.
When auth().onAuthStateChanged() is first called. It will trigger with the initial Auth state. If the user is returning from an auth().signInWithRedirect() operation, the observer will wait for that operation to resolve before initially triggering.
新用户签名时.
When a new user signs.
已经登录的用户退出时.
When an already signed in user signs out.
这篇关于在电子邮件中验证邮件时,不会调用onAuthStateChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!