【发布时间】: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