pythonfirebase-realtime-databasefirebase-authenticationpyrebase

List all users from Firebase Authentication


I am currently using the Pyrebase wrapper to get information (such as their email and created date) of all users. I tried looking through the documentation and cross reference it to Pyrebase documentation however i don't seem to get what i'm looking for. Currently i have tried this:

import pyrebase

config={all required information, including path to service account .json file}
firebase=pyrebase.initialize_app(config)
db=firebase.database()
auth=firebase.auth()


extract_user = db.child('users').child('userId').get()

for x in extract_user.each():
    print(x.val())
    
    auth.get_account_info(user[x.val()])

However i still failed, i know im missing something but im not sure what.

Note: I saved the users userID in the database under userId. So i looped through each and every ID to be used in the 'get_account_info'

Any suggestions or ways i can get this to be done?


Solution

  • The db.child('users').child('userId').get() in your code reads users from the Realtime Database, where they'll only exist if your application added the there explicitly. Adding a user to Firebase Authentication does not automatically also add it to the Realtime Database.

    While Pyrebase allows you to initialize it with a service account, it doesn't replicate all administrative functionality of the Firebase Admin SDKs. As far as I can see in Pyrebase's code, Pyrebase's does not implement a way to list users.

    Consider using the Firebase Admin SDK, which has a built-in API to list users.