Firebase经过身份验证的用户无法写入数据库

时间:2016-11-02 09:38:26

标签: ios firebase firebase-realtime-database firebase-authentication firebase-security

我有以下数据库规则:

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

在iOS端:

        FIRAuth.auth()?.signInWithCustomToken(token, completion: { (user, error) in

        if error == nil {

            let userRef = FIRDatabase.database().reference().child("users").child(user!.uid)

            userRef.observeSingleEventOfType(.Value, withBlock: { (snap) in
                //....

                printD("working...")

                }, withCancelBlock: { (error) in
                    printD(error)
            })
        }
    })
}

控制台输出:

[Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied}]

打印用户!.uid给出"ODEzYjIzNzctMTFmMC00NjhhLWIxNTAtZjExN2I0MXXXXXX1"

0 个答案:

没有答案