thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.05k stars 525 forks source link

`db.child("data").get(token).val()` returns `None` even after setting. #383

Closed writeblankspace closed 3 years ago

writeblankspace commented 3 years ago

Here's my configuration (I keep my keys in an env)

config = {
  "apiKey": APIKEY,
  "authDomain": "lumen-dbot.firebaseapp.com",
  "databaseURL": "https://lumen-dbot-default-rtdb.europe-west1.firebasedatabase.app/",
  "storageBucket": "lumen-dbot.appspot.com",
  "serviceAccount": "db/lumen-dbot-firebase-adminsdk-1u859-df6cc00a59.json"
}

firebase = pyrebase.initialize_app(config)

auth = firebase.auth()
#authenticate a user
email = EMAIL
password = PASSWORD
user = auth.sign_in_with_email_and_password(email, password)
token = user['idToken']

# setup the database
fdb = firebase.database()

I'm pretty sure I did everything right; my email has Owner perms and I took the API key from 'Web API Key' in project settings.

I receive no errors aside from this code returning None:

if fdb.child("data").get(token).val() == None:
  fdb.child("data").set({}, token)

print(fdb.child("data").get(token).val())
return fdb.child("data").get(token).val()
writeblankspace commented 3 years ago

Actually it worked once I set it to a dict with something in it. The empty dict ends up not setting it to anything at all.