Q:

How to set up firebase custom claims from command line?

People have looked at similar issues before, but the latest I could find is 2018.
How do you set custom claims in firebase with the terminal?
I want to execute a script that sets users with specified emails to admins.
The script is:
const admin = require('firebase-admin');
admin.initializeApp()

const adminEmails = [
    "test1@test.com",
    "test2@test.com",
    "test3@test.com"
]

for (let adminEmail of adminEmails) {
    admin.auth().getUserByEmail(adminEmail)
    .then(function(userRecord) {
      // See the UserRecord reference doc for the contents of userRecord.
      console.log('Successfully fetched user data:', userRecord.toJSON());
      admin.auth().setCustomUserClaims(userRecord.uid, {admin: true}).then(() => {
          // The new custom claims will propagate to the user's ID token the
          // next time a new one is issued.
        });
    })
    .catch(function(error) {
     console.log('Error fetching user data:', error);
    });
}

When I run this with node, I get invalid credential - how do I authenticate from the command line and is it possible to run a script that creates custom claims like this?

A:

The error message suggests that you need to pass an object with service account credentials to initializeApp() to configure the Admin SDK, or set the GOOGLE_APPLICATION_CREDENTIALS env var, as described in the documentation.

