能够在Firebase中对用户进行身份验证,但不能在Firebase数据库中存储用户数据

时间:2018-08-19 17:51:45

标签: swift firebase firebase-realtime-database firebase-authentication

我能够在Firebase身份验证中对用户进行身份验证,但不能像在Firebase数据库中的名字和姓氏一样存储他们的数据。我编写的代码可能有问题吗?

Auth.auth().createUser(withEmail: userEmail, password: userPassword) { (user, error) in

        if let error = error
        {
            print(error.localizedDescription)
            self.showMessage(messageToDisplay: error.localizedDescription)
            return
        }

           if let user = user {
            var databaseReference: DatabaseReference!
            databaseReference = Database.database().reference()

            let userDetails:[String:String] = ["firstName":firstName, "lastName":lastName]
            databaseReference.child("users").child(user.uid).setValue(["userDetails":userDetails])

screenshoot of problem

screenshoot of authenticated users

1 个答案:

答案 0 :(得分:0)

尝试为此设置实时数据库规则:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}