简体   繁体   English

firebase 创建用户 promise

[英]firebase create user promise

I'm trying to create users in Firebase and add some data in the database using real-time datase.我正在尝试在 Firebase 中创建用户,并使用实时数据集在数据库中添加一些数据。 I'm protecting the database with a rule only allowing the current user to insert data in his table.我用一条规则保护数据库,只允许当前用户在他的表中插入数据。 Even I'm using the promise I got a message saying "PERMISION DENIED".即使我使用的是 promise,我也收到一条消息说“权限被拒绝”。 This is my code:这是我的代码:

firebase.auth().createUserWithEmailAndPassword(email, password)
 .then( user => {
        const db = firebase.database();
        const customer = db.ref().child('customers');
        const key = firebase.auth().currentUser.uid;

        customer.child(key).set({
            name : email,
            pwd : password,
            isRegistered : false,       
        });

How can I modify the data right after the user is created?如何在创建用户后立即修改数据?

Thanks folks谢谢大家

Edit2: these are the rules Edit2:这些是规则

{
  "rules": {
    "customers": {
      "$uid": {
        ".read": "auth.uid === $uid",
        ".write": "auth.uid === $uid"
      }
    }
  }
}

Considering the edit you made are after Doug's comment, your security rules should look more like:考虑到您所做的编辑是在 Doug 的评论之后进行的,您的安全规则应该更像是:

{
  "rules": {
    "customers": {
      "$uid": {
        ".read": "auth.uid === $uid",
        ".write": "auth.uid === $uid"
      }
    }
  }
}

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

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