Search code examples
javascriptfirebasefirebase-authenticationfirebase-admin

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.


Solution

  • 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});
    

    As others have pointed out the API has changed and the current way to set custom claims from Node.js is:

    
    getAuth()
      .setCustomUserClaims(uid, { admin: true })
      .then(() => {
        // The new custom claims will propagate to the user's ID token the
        // next time a new one is issued.
      });
    

    Check the linked documentation for more code samples, that are also more likely to be up to date than anything I type here. :)