首页 > 解决方案 > Firebase 数据库不存储用户信息

问题描述

出于某种原因,没有任何内容存储到数据库中,我一直在使用相同的代码,并且在我不明白为什么它现在不起作用之前它可以工作

这是怎么做的:

//auth process above
                    ProgressHUD.showSuccess()
                    let when = DispatchTime.now() + 1
                    DispatchQueue.main.asyncAfter(deadline: when){
                        ProgressHUD.dismiss()
                        self.storeUserData(userId: (user?.user.uid)!) //original was (user?.uid)! but it seems that google has change it
                        KeychainWrapper.standard.set((user?.user.uid)!, forKey: "uid")
                        let TBVC = mainTabBarController()
                        self.present(TBVC, animated: true, completion: nil)
                    }
                }
            })
        }
    }

    func storeUserData(userId: String) {
        Database.database().reference().child("users").child(userId).setValue([
            "username": username.text,
            "password": password.text,
            "email": email.text
            ])
    }

标签: swiftfirebasefirebase-realtime-database

解决方案


我会这样做并完成以查看错误

let dic = [
        "username": username.text,
        "password": password.text,
        "email": email.text
        ]

Database.database().reference().child("users").child(userId).setValue(dic, withCompletionBlock: { (error, ref) in

     print(error) // check error and see
 })

推荐阅读