You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The token created with with custom claims by admin.auth().createCustomToken(uid, additionalClaims) are encoded in base64 and getIdTokenResult is decoding it on the client but the base64 decoding causes issues with the UTF-8 encoded strings.
Steps to reproduce:
Authenticate user with a custom token with utf-8 claims:
user.getIdTokenResult(false).then(idToken=>{const{ role }=idToken.claims// role here is bad encoded
As a workaround the encoded role with base64 on the server and decoding it with the following function:
functionb64DecodeUnicode(str){// Going backwards: from bytestream, to percent-encoding, to original string.returndecodeURIComponent(atob(str).split('').map(function(c){return'%'+('00'+c.charCodeAt(0).toString(16)).slice(-2);}).join('')).trim();}