![](/img/trans.png)
[英]Email and Password Signup using firebase in a react app , the displayName of the user appears to be null on the initial render. How can I fix this?
[英]Update displayName while signup Firebase Flutter
我希望應用displayName
在用戶注冊時保存顯示名稱
我試過了:
Future<void> signUp() async {
try {
FirebaseUser user = (await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email.text, password: password.text))
.user;
UserUpdateInfo userUpdateInfo = new UserUpdateInfo();
userUpdateInfo.displayName = name.text;
await user.reload();
showInSnackBar("User name ${user.displayName}");
try {
await user.sendEmailVerification();
showInSnackBar("Email verification sent");
} catch (e) {
print(e);
}
} catch (e) {
String errorCode = e.code;
print(e);
if (errorCode == "ERROR_EMAIL_ALREADY_IN_USE") {
showInSnackBar("This email is already in use");
} else {
showInSnackBar("Somthing went wrong! Try again later");
}
}
}
使用此方法, SnakBar
為displayName
返回 null
設置userUpdateInfo.displayName = name.text
不足以實際更改用戶帳戶的名稱。 您必須調用updateProfile()並將UserUpdateInfo object傳遞給它,以便實際更改帳戶。
await user.updateProfile(userUpdateInfo)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.