node.js - 如何从命令行设置 Firebase 自定义声明?
问题描述
人们以前看过类似的问题,但我能找到的最新的是 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()
来配置 Admin SDK,或设置GOOGLE_APPLICATION_CREDENTIALS
env var,如文档中所述。
推荐阅读
- r - 在 R 中使用“复制”时尝试存储估计值
- pandas - 比较熊猫中的两个数据框
- codeigniter - 如何从codeigniter中的多个表中选择数据
- html - 我的宽度没有改变,迫使我的 div 分成两行
- node.js - 帐号关联成功后的错误信息
- c# - 如何从 C# Cmdlet 访问底层 PowerShell 运行空间?
- node.js - 节点 js 应用程序的 npm 启动时出错:找不到 toposcache.json
- python - 如何在 Python 的 Tkinter 的类中使用 slider.on_changed()
- python - Mock / create_autospec:验证参数类型
- java - 使用 DSM(声明式流映射)将 XML 文件解组为对象