Node.js 如何从命令行设置firebase自定义声明?

Node.js 如何从命令行设置firebase自定义声明?,node.js,firebase,firebase-authentication,firebase-admin,Node.js,Firebase,Firebase Authentication,Firebase Admin,人们以前也看过类似的问题,但我能找到的最新问题是2018年 如何使用终端在firebase中设置自定义声明 我想执行一个脚本,将具有指定电子邮件的用户设置为管理员 剧本是: const admin = require('firebase-admin'); admin.initializeApp() const adminEmails = [ "test1@test.com", "test2@test.com", "test3@test.com" ] for (let

人们以前也看过类似的问题,但我能找到的最新问题是2018年

如何使用终端在firebase中设置自定义声明

我想执行一个脚本,将具有指定电子邮件的用户设置为管理员

剧本是:

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);
    });
}

当我使用节点运行此操作时,我获得的凭据无效-如何从命令行进行身份验证,以及是否可以运行这样创建自定义声明的脚本?

错误消息建议您需要将具有服务帐户凭据的对象传递到
initializeApp()
,以配置管理员SDK,或者设置
GOOGLE\u应用程序\u凭据
env var,如中所述。

Firebase CLI不会帮助您运行脚本或处理自定义声明。我不明白你为什么在这里提到云函数,因为你的代码没有声明函数。请编辑此问题,以便更清楚地了解您正在努力完成的任务和未按预期方式完成的任务。感谢您查看我的问题道格-我很喜欢您的教程视频!将编辑