Search code examples
firebasefirebase-authenticationjwttoken

Add data to Firebase ID token


Is it possible to add small pieces of data to the Firebase ID Token? For example, it seems some fields like uid, email, displayName and phoneNumber are part of it. Could I add firstName and lastName fields too?

The use case is every now and then, I need to access the first and last names of the logged in user. If not the ID token, where else can I store them, if at all?

I was considering storing in custom claims, but it feels like I'd be abusing the feature.


Solution

  • You can't add fields to an ID token other than what's listed in the documentation. The only way you can provide additional information is through using custom claims. A custom claims payload is restricted to 1000 bytes, so it's not very flexible.

    Sometimes it's more appropriate to simply store additional information about the user in a database, keyed off the user's UID.