人们以前曾研究过类似的问题,但我能找到的最新时间是2018年。
您如何通过终端在Firebase中设置自定义声明?
我想执行一个脚本,该脚本将具有指定电子邮件的用户设置为管理员。
脚本是:
const admin = require('firebase-admin');
admin.initializeApp()
const adminEmails = [
"[email protected]",
"[email protected]",
"[email protected]"
]
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
中的说明设置documentation env var。