【发布时间】:2021-11-14 06:07:24
【问题描述】:
我正在尝试在我的应用程序中实现一个正常的身份验证系统,但我想为每个用户创建一个新字段,即“uniqueName”,以便用户可以在他们的朋友列表中搜索和添加彼此。我正在考虑在 uniqueName 的注册表单中添加一个 textField 并更新我的 User 类,以这种方式添加一个新字符串:
class User {
String email;
String name;
String uniqueName;
String userID;
String profilePictureURL;
String appIdentifier;
...
}
现在,因为我有这个方法来注册电子邮件和密码:
static firebaseSignUpWithEmailAndPassword(String emailAddress,String password,File? image,String name,) async {
try {
auth.UserCredential result = await auth.FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: emailAddress, password: password);
String profilePicUrl = '';
if (image != null) {
await updateProgress('Uploading image, Please wait...');
profilePicUrl =
await uploadUserImageToFireStorage(image, result.user?.uid ?? '');
}
User user = User(
email: emailAddress,
name: name,
userID: result.user?.uid ?? '',
profilePictureURL: profilePicUrl);
String? errorMessage = await firebaseCreateNewUser(user);
if (errorMessage == null) {
return user;
} else {
return 'Couldn\'t sign up for firebase, Please try again.';
}
}
我必须如何修改它才能在注册中添加这个新字段?由于在数据库中创建新用户之前,我必须检查用户插入的 uniqueName 是否有效,我该怎么办?
此外,我认为如果在填写表格的同时进行此检查会很酷,我该怎么做? (这不是必须的)
谢谢大家的回答
【问题讨论】:
-
Firebase 实时数据库和 Cloud Firestore 是两个独立的数据库。请仅使用相关标签标记您的问题,不要同时使用两者。
标签: firebase flutter google-cloud-firestore firebase-authentication