In order to set a custom claim, one uses:
admin.auth().setCustomUserClaims(uid,{claim:value});
There does exist
admin.auth().updateUser(uid,{claim:value});
...but I'm not exactly clear on how the two are different, and neither one seems to get at actually removing a previously applied custom claim.
From the documentation:
You can delete a user's custom claims by passing null for
customClaims.
So this should delete the claim:
admin.auth().updateUser(uid, {claim: null});
@FrankvanPuffelen's answer 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 that has no claim property.
Setting custom claims has now been moved to the setCustomUserClaims method.
You set them by doing...
admin.auth().setCustomUserClaims(uid, { admin: true });
...and the only way you can remove one is by setting the whole object to null. There seems to be no way to selectively remove one claim if there are multiple.
admin.auth().setCustomUserClaims(uid, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With