nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺
258 stars 64 forks source link

Firebase.init() throws error when JSON config has no `databaseURL` key #57

Open phlummox opened 1 year ago

phlummox commented 1 year ago

Make sure these boxes are checked before submitting your issue:

[x] Check that your version of Python is 3.4+ [x] Check that you are on the newest version of Pyrebase [x] Check that Email/password provider is enabled in your Firebase dashboard under Auth -> Sign In Method.

At least on my current Firebase project, the JSON configuration got from the Firebase console has no "databaseURL" key.

Instead, the keys are:

{
 "apiKey": ...,
 "authDomain": ...,
 "projectId": ...,
 "storageBucket": .,
 "messagingSenderId": ...,
 "appId": ...,
 "measurementId": ...
}

That means that the following line of pyrebase.Firebase.__init__ throws an exception:

https://github.com/nhorvath/Pyrebase4/blob/3e00233f043b326e2e64cad663b18b580d13b8b3/pyrebase/pyrebase.py#L36

The fix seems to be to replace that line with the following code

        if "databaseURL" in config:
          self.database_url = config["databaseURL"]

but I don't know if that has knock-on consequences elsewhere in the codebase.

AsifArmanRahman commented 1 year ago

At least on my current Firebase project, the JSON configuration got from the Firebase console has no "databaseURL" key.

In previous days, the databaseURL key came by default in the firebase configuration json. The library still follows that pattern, and it makes sense to so, because it'll enable usage of all sub-modules at once.

I maintain a version of pyrebase/pyrebase4 repo, and in the documentation for that project, I've mentioned about the key here.

Strain-solutions commented 1 year ago

Coming across the same issue I came across a SO post that the URL is no longer needed to authenticate. So I passed None for both databaseURL and storageBucket (since Im not using cloud storage and Im using firestore not the RTB). I could authenticate just fine.

config = {
  "apiKey": "myAPIKeyGoesHere",
  "authDomain": "myFIrebaseAPP.firebaseapp.com",
  "databaseURL":None,
  'storageBucket':None,
}

firebase = pyrebase.initialize_app(config)

auth = firebase.auth()

user = auth.sign_in_with_email_and_password('myGmailEmail@gmail.com', '123456789')
print(user)