【发布时间】:2020-09-18 02:47:21
【问题描述】:
所以我有一个用例,其中用户可能需要多个自定义声明,但在应用程序的不同点添加,即用户可以既是店主又是店主,或者他们可能只是店主或只是用户.
我通过文档了解到,当您分配新的自定义声明时,它会覆盖原始声明,因此我需要阅读用户当前拥有的声明。这就是我卡住的地方...在我收到声明后如何将它们重新写回给用户?
exports.onGameManagement = functions.database.ref("Core/CoreGames/{game}/teams/committee").onCreate((snapshot,context)=>{
const position = snapshot.key;
const uid = snapshot.val();
const game = context.params.game;
if(position=="gLead"||position=="depGameLead"){
//NEEDS ADMIN RIGHTS
//ADD TOKEN WRITE RIGHTS. - check for current claims
admin.auth().getUser(uid).then((userRecord)=>{
//got the users claims
console.log(userRecord.customClaims);
//how do i add this array of claims to the setCustomUserClaims() method?
admin.auth().setCustomUserClaims(uid, {gameAdmin: true, userRecord.customClaims}).then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
});
})
}else{
}
})
我怀疑这是一个非常简单的解决方法,但我似乎无法在任何地方找到任何关于如何处理在不同时间添加多个声明的示例......可以这么说。非常感谢您提前提供的帮助。
【问题讨论】:
标签: javascript firebase firebase-authentication google-cloud-functions firebase-admin