Firebase 电子邮件验证 Flutter
Firebase Email Validation Flutter
我有这段代码可以注册:
Future<String> signUp({String email, String password}) async {
try{
await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
return "Signed up";
} on FirebaseAuthException catch(e){
print("no se puede crear");
return e.message;
}
}
我需要实现来自 firebase 的验证邮件,这已经被问了很多,我在研究时想到了这个,一些代码已被弃用,我很难找到指导:
Future<String> signUp({String email, String password}) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
try {
await user.sendEmailVerification();
return user.uid;
} catch (e) {
print("An error occured while trying to send email verification");
print(e.message);
}
}
}
但不知道如何实现它,因为它会抛出:
A value of type 'UserCredential' can't be assigned to a variable of type 'FirebaseUser'.
createUserWithEmailAndPassword doesn't return a FirebaseUser object. As you can see from the linked API documentation, it yields a UserCrediental 对象。这就是错误消息试图告诉您的内容 - 您不能将 UserCredential 分配给 FirebaseUser 类型的变量。
如果您想从 UserCredential 中获取 FirebaseUser 对象,您只需使用其 user 属性.
UserCredential credential = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = credential.user;
我有这段代码可以注册:
Future<String> signUp({String email, String password}) async {
try{
await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
return "Signed up";
} on FirebaseAuthException catch(e){
print("no se puede crear");
return e.message;
}
}
我需要实现来自 firebase 的验证邮件,这已经被问了很多,我在研究时想到了这个,一些代码已被弃用,我很难找到指导:
Future<String> signUp({String email, String password}) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
try {
await user.sendEmailVerification();
return user.uid;
} catch (e) {
print("An error occured while trying to send email verification");
print(e.message);
}
}
}
但不知道如何实现它,因为它会抛出:
A value of type 'UserCredential' can't be assigned to a variable of type 'FirebaseUser'.
createUserWithEmailAndPassword doesn't return a FirebaseUser object. As you can see from the linked API documentation, it yields a UserCrediental 对象。这就是错误消息试图告诉您的内容 - 您不能将 UserCredential 分配给 FirebaseUser 类型的变量。
如果您想从 UserCredential 中获取 FirebaseUser 对象,您只需使用其 user 属性.
UserCredential credential = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = credential.user;