Title: Firebase admin auth listAllUsers give - failed to determine project ID
Tags: reactjs;firebase;google-cloud-firestore;firebase-authentication;firebase-admin
Question: Using Node - v12.16.1
React + Firebase
this.adminSDK = admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://APP_NAME.firebaseio.com"
console.log(this.adminSDK.name); //gives [DEFAULT]
//code below gives error
.auth()
.listUsers()
.then(function (listUsersResult) {
this.listOFUsers = listUsersResult;
.catch(function (error) {
console.log("Error listing users:", error);
adminSDK.name gives = [DEFAULT] in console
listALLUsers gives error :
Error listing users: Error: Failed to determine project ID: Error while making request: Failed to fetch. Error code: james51@example.com [as constructor] (error.js:42)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (error.js:88)
at new FirebaseAppError (error.js:123)
at credential.js:183
I have set "GOOGLE_APPLICATION_CREDENTIALS"
Tried using SERVICE ACCOUNT credential method to initialize adminSDK, which gives Z_DATA error
Comment: @HiranyaJayathilaka Providing my service json. PLease have a look.
"type": "
"project_id": "
"private_key_id": "",
"private_key": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----\n",
"client_email": "
"client_id":
"auth_uri": "
"token_uri":
"auth_provider_x509_cert_url":
"client_x509_cert_url":

Comment: Figured it out. For anyone facing the same error:
I was running this on Client side server. Fix - Run on server and fetch response from API (I used Firebase cloud functions to deploy API)
@HiranyaJayathilaka Thank you for your help :)

Comment: It looks like your service account json file is invalid or corrupted. Can you check if it contains the `project_id`, `private_key` and `client_email` fields?

Comment: That looks correct. If your `GOOGLE_APPLICATION_CREDENTIALS` environment variable contains the path to that file, then everything should work without issues.

Here is the accepted answer: Figured it out. For anyone facing the same error: I was running this on Client side server. Fix - Run on server and fetch response from API (I used Firebase cloud functions to deploy API)


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:04/13/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<reactjs><firebase><google-cloud-firestore><firebase-authentication><firebase-admin>', 'Title': 'Firebase admin auth listAllUsers give - failed to determine project ID', 'ViewCount': 282, 'id': 61182331, 'user_AboutMe': None, 'user_AccountId': 18267437.0, 'user_DisplayName': 'gameDeveloper', 'user_Reputation': 22.0, 'user_Views': 2.0, 'user_id': 13298850.0}}