登录后,我希望我的应用程序在Firebase数据库中创建一个新字段,其中包含以用户名命名的子项 .
if let email = emailField.text, let pass = passwordField.text {
// Check if it's sign in or register
if isLogin {
// Sign in the user with Firebase
Auth.auth().signIn(withEmail: email, password: pass, completion: { (user, error) in
// Check that user isn't nil
if let u = user {
// User is found, go to home screen
self.ref?.child(email).childByAutoId().setValue("1")
self.performSegue(withIdentifier: "goHome", sender: self)
print("yes")
}
当我尝试这样做时,它给出了一个名为 SIGABART
的错误,我认为这与错误连接正确无关 .
然而,如果我删除这一行:self.ref?.child(email).childByAutoId() . setValue(“1”)
或者将 email
字段更改为 "test"
之类的随机字符串,它可以正常工作并显示在Firebase中 .
4 回答
如果我没记错的话,你不能在节点名称中使用符号
@
. 这是第一个问题 . 你可以做另一件事,我认为更好,方式:你需要创建用户来反对:
您可以通过以下步骤执行此操作:
例如,您的注册页面将包含3
UITextFields
:userEmail
,userLogin
和userPassword
.像这样 . 希望能帮助到你 .
Firebase Auth不允许您存储此类值 . 您需要将其保存到Firebase数据库或其他服务中 . 例如在Firebase数据库中:
您应该在数据库中保存用户名值 . 像这样的东西:
(我在手机上,所以通话可能不是那样,但应该非常接近)
干杯 .
斯威夫特4: