eli*_*003 8 firebase firebase-authentication flutter
当用户在我的应用程序中注册时,他会收到一封验证电子邮件。-listeneronAuthStateChanged在使用创建用户时被调用createUserWithEmailAndPassword,但在电子邮件验证后不会被调用。
我有一个单独的类来处理所有身份验证。以下方法是注册用户
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;
}
Run Code Online (Sandbox Code Playgroud)
在我的StatefulWidget中使用这个方法调用这个方法
void _signUpUser() async {
try {
await Auth().signUpUser(_email, _password)
..sendEmailVerification();
} catch (e) {
print(e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
并按照我的方法onAuthStateChanged设置initStateStatefulWidget
FirebaseAuth.instance.onAuthStateChanged.listen((user) {
print("Auth State Changed!");
if (user.isEmailVerified) {
print("EMail verified!");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3601 次 |
| 最近记录: |