在 firebase 身份验证中,有没有办法删除自定义声明?

In firebase authentication, is there a way to remove a custom claim?

要设置自定义声明,请使用:

admin.auth().setCustomUserClaims(uid,{claim:value});

确实存在

admin.auth().updateUser(uid,{claim:value});

...但我不太清楚两者有何不同,而且似乎都没有真正删除先前应用的自定义声明。

来自documentation

You can delete a user's custom claims by passing null for customClaims.

所以这应该删除声明:

admin.auth().updateUser(uid, {claim: null});

我认为您不能为此使用 updateUser,我认为您仍然需要调用

admin.auth().setCustomUserClaims(uid, {claim:null}); 

no doubt was the correct one at the time he answered it, however, as it stands today (Nov 30, 2020) the 2nd parameter of the updateUser method, called properties, is an UpdateRequest interface 没有 claim 属性.

设置自定义声明现已移至 the setCustomUserClaims method

您可以通过...设置它们...

admin.auth().setCustomUserClaims(uid, { admin: true });

...删除一个对象的唯一方法是将整个对象设置为 null。如果有多个声明,似乎没有办法有选择地删除一个声明。

admin.auth().setCustomUserClaims(uid, null);