Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 250
ecalvo Avatar asked Jan 09 '18 19:01

ecalvo


2 Answers

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});
like image 80
Frank van Puffelen Avatar answered Sep 19 '22 21:09

Frank van Puffelen


@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); 
like image 42
benomatis Avatar answered Sep 21 '22 21:09

benomatis