0

I have some custom claims like

{
  claim1: true,
  claim2: true,
}

I want to remove one claim

{
  claim2: true,
}

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

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

but update user not have claim property.

if I use this, this remove the previous claims and also set null, not removed

admin.auth().setCustomUserClaims(context.auth.uid, {claim1: null});
{
  claim1: null,
}
Constantin Beer
  • 5,447
  • 6
  • 25
  • 43

2 Answers2

1
  1. Get the UserRecord for the user's UID with getUser().
  2. Get their existing custom claims from customClaims property.
  3. Make changes to it as needed.
  4. Update the modified claims with setCustomUserClaims().
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
0

Delete the claim in question.

admin.auth().getUser(uid).then((user) => {

    const userCustomClaims = user.customClaims;

    if (userCustomClaims["claim1"]) {

        delete userCustomClaims["claim1"];
        return admin.auth().setCustomUserClaims(user.uid, userCustomClaims);

    }
}).catch((error) => {

    console.error(error);

});

CMIIW

Itang Sanjana
  • 649
  • 5
  • 8