【问题标题】:How to set up firebase custom claims from command line?如何从命令行设置 Firebase 自定义声明?
【发布时间】:2020-05-21 16:37:57
【问题描述】:

人们以前也看过类似的问题,但我能找到的最新的是 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);
    });
}

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

【问题讨论】:

  • Firebase CLI 不会帮助您运行脚本或处理自定义声明。我很困惑你为什么在这里提到云函数,因为你的代码没有声明一个函数。请编辑问题,以更清楚地说明您要完成的工作以及未按预期方式工作的内容。
  • 感谢您查看我的问题 Doug - 我很喜欢您的教程视频!将编辑

标签: node.js firebase firebase-authentication firebase-admin


【解决方案1】:

错误消息表明您需要将具有服务帐户凭据的对象传递给 initializeApp() 以配置 Admin SDK,或设置 GOOGLE_APPLICATION_CREDENTIALS env var,如 documentation 中所述。

【讨论】:

    猜你喜欢
    • 2019-07-02
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2020-06-28
    • 2017-09-05
    • 2019-12-17
    • 1970-01-01
    • 2018-09-18
    相关资源
    最近更新 更多