使用Firebase进行Flutter用户注册:添加额外的用户信息(年龄,用户名) [英] Flutter user registration with Firebase: Add extra user information (age, username)
问题描述
在phpMySQL背景下,我有点迷路了.
With a phpMySQL background, I'm a little bit lost.
按照教程,我已经成功地使用Flutter和Firebase Auth(简单的电子邮件/密码方法)创建了注册过程.
I've successfully created a registration process with Flutter and Firebase Auth (simple email/password method) following a tutorial.
我想在注册表格中添加一个用户名"和年龄"字段.
I would like add a "username" and "age" field to the registration form.
在Firebase中,我创建了一个名为用户"的数据库,其中有一个字符串键入"userid",该字符串为空.但这是否有必要?我下一步该怎么办?它如何映射到身份验证表中的用户UID?如何推动它并使用Flutter进行检索?
In Firebase I've created a database called "users", and in it a String typed "userid" that's blank. But is it even necessary? What do I do next? How is it mapped to the User UID in the authentication table? How do I push it and retrieve it with Flutter?
我对这篇文章的浏览无济于事使用firebase添加额外的用户信息
I've explored this post to no avail Add extra User Information with firebase
如果有帮助,我的身份验证文件将包含以下内容:
If that helps, my authentication file contains this:
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Future<String> signIn(String email, String password) async {
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
return user.uid;
}
Future<String> signUp(String email, String password) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
return user.uid;
}
尝试过:
Future<String> signUp(String email, String password) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
Firestore.instance.collection('users').document().setData({ 'userid': user.uid, 'displayName': 'bobby' });
return user.uid;
}
但是它会引发错误:
5.17.0 - [Firebase/Firestore][I-FST000001] Write at users/-L_6e1CFkU1YchxsSPay failed: Missing or insufficient permissions.
推荐答案
好的,以上似乎都很好. 只需按照以下内容将数据库规则从false更改为true:
Ok seems the above is all good. Just had to change the Database rules from false to true as per the below post:
https://stackoverflow.com/a/46925637/3475894
这篇关于使用Firebase进行Flutter用户注册:添加额外的用户信息(年龄,用户名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!