I'm trying to use the firebase admin sdk but when I try to do this: admin.auth() it gives me an error saying Error:
The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services
The app is already initialized when I use the normal sdk, how to I initialize the admin-sdk so I can list all users?
Asked
Active
Viewed 367 times
1
Frank van Puffelen
- 499,950
- 69
- 739
- 734
Meir Biton
- 27
- 4
-
Can you edit your question to show the [minimal, complete/standalone code that any of us can run to reproduce the problem?](http://stackoverflow.com/help/mcve) – Frank van Puffelen Jun 09 '21 at 14:15
1 Answers
1
The Admin SDK is designed to be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. It is specifically not designed to be used in client-side code, as doing so will gives any user of your app privileged access to your entire Firebase project.
If you want to show a list of users in your app, the two common approaches are:
- Store the necessary information about the users in a cloud database (such as Cloud Firestore, or Realtime Database) and read it from there, using the server-side security rules of the database to ensure users can only access information they're authorized for.
- Wrap the necessary calls from the Admin SDK in a custom server-side API that you create (for example, on a server you control, or in Cloud Functions), using the custom code to ensure users can only access information they're authorized for.
Also see:
Frank van Puffelen
- 499,950
- 69
- 739
- 734