简体   繁体   English

使用Firebase进行Flutter用户注册:添加额外的用户信息(年龄,用户名)

[英]Flutter user registration with Firebase: Add extra user information (age, username)

With a phpMySQL background, I'm a little bit lost. 有了phpMySQL背景,我有点迷路了。

I've successfully created a registration process with Flutter and Firebase Auth (simple email/password method) following a tutorial. 我已按照教程成功使用Flutter和Firebase Auth(简单的电子邮件/密码方法)创建了注册过程。

I would like add a "username" and "age" field to the registration form. 我想在注册表格中添加“用户名”和“年龄”字段。

In Firebase I've created a database called "users", and in it a String typed "userid" that's blank. 在Firebase中,我创建了一个名为“ users”的数据库,并且在其中输入了一个字符串,键入“ userid”为空。 But is it even necessary? 但这是否有必要? What do I do next? 接下来我该怎么办? How is it mapped to the User UID in the authentication table? 它如何映射到身份验证表中的用户UID? How do I push it and retrieve it with Flutter? 如何推动它并使用Flutter进行检索?

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;
  }

Have tried this: 尝试过这个:

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;
  }

But it throws an error: 但这会引发错误:

5.17.0 - [Firebase/Firestore][I-FST000001] Write at users/-L_6e1CFkU1YchxsSPay failed: Missing or insufficient permissions.

Ok seems the above is all good. 好的,以上似乎都很好。 Just had to change the Database rules from false to true as per the below post: 只需按照以下内容将数据库规则从false更改为true:

https://stackoverflow.com/a/46925637/3475894 https://stackoverflow.com/a/46925637/3475894

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM