I am trying to save data in my firebase realtime database using this rule:
{
"rules": {
"users": {
"$uid": {
// Allow only authenticated content owners access to their data
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid",
},
},
},
}
I need to create a child of users and name it the uid of that user. So, I did this:
user=auth.sign_in_with_email_and_password('email', 'password')
database.child('users').child(user['localId']).set("nahid",user['localId'])
but when I run this, I get this error:
requests.exceptions.HTTPError: [Errno 401 Client Error: Unauthorized for url: https://khelobd-6f730-default-rtdb.firebaseio.com/users/7Km7srPfqqccZwa0On5i2QaJDUi2.json?auth=7Km7srPfqqccZwa0On5i2QaJDUi2] {
"error" : "Could not parse auth token."
}
How can I solve this?
The ?auth=
param does not seems to be user's Firebase ID Token but the UID itself. Try changing user['localId']
in set()
to user['idToken']
:
user=auth.sign_in_with_email_and_password('email', 'password')
database.child('users').child(user['localId']).set("nahid",user['idToken'])
# ^^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.