Ivan Chernykh
Ivan Chernykh

Reputation: 42176

Firebase auth customClaims not exists for user created with help of createCustomToken()

I want to store some secret data in user' customClaims. I create a token on server with:

var customToken = createCustomToken(uniqueId, {mySecretData:"VerySecretData"}),

sending it to my app , logging user in with signInWithCustomToken(customToken), and it works fine,

BUT, when i am fetching user later on server by calling admin's getUser(uniqueId) and trying to see its customClaims there is nothing, undefined.

The interesting thing is that i do see this secret data in callable function context' auth property' token object.

Question: why developerClaims are not user' customClaims ?

Reference: https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createcustomtoken

Upvotes: 0

Views: 432

Answers (1)

Hiranya Jayathilaka
Hiranya Jayathilaka

Reputation: 7438

Claims added via createCustomToken() only exist in the Auth token issued by the Firebase Auth. They are not stored anywhere beyond that, and getUser() response will not include them. You should use the setCustomUserClaims() to get the behavior you've indicated.

Upvotes: 1

Related Questions