我试图创建一个注册函数,但我得到这个错误“示例成员'用户'不能使用静态访问。”为此行
字符串userId =用户凭证.用户!.uid;
I am uploading error page here
这是密码
final auth = FirebaseAuth.instance;
final db = FirebaseFirestore.instance;
Future<bool> register(String email, String password, String username) async {
try {
await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: email, password: password);
String userId = UserCredential.user!.uid;
final userRef = FirebaseFirestore.instance.collection('users').doc(userId);
await userRef.set({
'username': username,
'email': email,
});
return true;
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
print('Password provided is too weak');
global.error = "Password provided is too weak";
} else if (e.code == 'email-already-in-use') {
global.error = "The account already exist for that email.";
print('The account already exist for that email.');
}
return false;
} catch (e) {
print(e.toString());
return false;
}
} ```
1条答案
按热度按时间k97glaaz1#
通过查看creating a user with email+password和
UserCredentials
class文档中的代码示例,似乎获取新创建的用户及其UID的正确方法是: