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 1,851 times
1

Frank van Puffelen
- 565,676
- 79
- 828
- 807

Meir Biton
- 27
- 6
-
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
2
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
- 565,676
- 79
- 828
- 807
-
None of the links you provided have good, date-related (= version related) answers. One of those is actually to a JAVA question (not JAVAscript) You actually linked inside your answer to this page. – Sagive Aug 06 '22 at 12:44
-
2Sorry you found this answer not useful @Sagive. If you're still struggling to list all users from Firebase in your JavaScript code after reading the linked answers, it might be best to post a new question with a [minimal repro](http://stackoverflow.com/help/mcve) of where you got stuck, rather than downvote an answer that apparently was useful to others *when* they were looking for how to implement that use-case. ¯\\_(ツ)_/¯ – Frank van Puffelen Aug 06 '22 at 13:53