简体   繁体   English

为什么不在 Cloud Firebase 中创建新集合?

[英]Why isn't a new collection being created in Cloud Firebase?

I've returned a promise 'db' to access the collection.我返回了一个 promise 'db' 来访问该集合。 The collection doesn't exist yet because when I allow the user to signup Firebase should automatically create the collection.该集合尚不存在,因为当我允许用户注册时 Firebase 应自动创建该集合。 I then created a doc by passing in a id so when I save to that document it's going to create an autoid for that document.然后我通过传入一个 id 创建了一个文档,因此当我保存到该文档时,它将为该文档创建一个 autoid。

I then set a property called email and then passed the email value to this.然后我设置了一个名为 email 的属性,然后将 email 值传递给它。 Now the document will have the same id as the users.现在文档将具有与用户相同的 id。

The problem is it isn't creating a new collection, any ideas?问题是它不是在创建一个新系列,有什么想法吗?

   function signup(){

  var userEmail = document.getElementById("email_field").value;
  var userPass = document.getElementById("password_field").value;

  firebase.auth().createUserWithEmailAndPassword(userEmail, userPass)(cred => {
    return db.collection('users').doc(cred.user.uid).set({
      email: document.getElementById("email_field").value
    }).then
  })
  .catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    window.alert("Error : " + errorMessage);
    // ...
  });
}

Here is what I set in Cloud Firebase Rules and allowed documents to be created:这是我在 Cloud Firebase 规则中设置的内容并允许创建文档:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
}
}

If you are not able to see any errors when calling the set method, I'd suggest you to use the firebase authenticatio triggers (to keep some logic separated and not a lot of promises in your current implementation)in that way you can make reference to the user information with the parameter that is given at the trigger如果您在调用 set 方法时看不到任何错误,我建议您使用firebase 身份验证触发器(在当前实现中保持一些逻辑分离而不是很多承诺),这样您可以参考使用触发器给出的参数到用户信息

PS: do you need that "then" at the db invocation? PS:你在 db 调用时需要那个“then”吗? (as doug has mentioned on his comment) (正如道格在他的评论中提到的)

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

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