nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺
248 stars 61 forks source link

Push with rtdb rules #31

Closed marcelomanzo closed 3 years ago

marcelomanzo commented 3 years ago

Please note that I am not using the service account.

I am using the following rules to my rtdb: { "rules": { "users": { "$user_id": { ".write": "$user_id === auth.uid", ".read": "$user_id === auth.uid" } } } }

And using the following code: firebase = pyrebase.initialize_app(config) auth = firebase.auth() user = auth.sign_in_with_email_and_password('peter@gmail.com', '***')

Get a reference to the database service

db = firebase.database()

data to save

data = { "name": "Mortimer 'Morty' Smith" }

Pass the user's idToken to the push method

results = db.child("users").child(user['localId']).push(data, user['idToken'])

I can write to the db, but it creates an additional node with the token: image

Is it possible to write to the db without the token?

marcelomanzo commented 3 years ago

Nevermind, using set instead of push works.