Hello everyone,
I failed to add the base_currency
to the idToken
using the post-login
trigger.
Based on the output that I’m receiving from the getSession()
methods from @auth0/nextjs-auth0@beta.14
, the idToken
is not containing the base_currency
attribute.
My application is Single Page Application (SPA) and using Google OAuth 2.0 and custom database for authentication.
Below is the step that I’ve done to add the base_currency
to the idToken
.
I have added the base_currency
to the user_metadata
and app_metadata
in the User Management > Users.
{
"base_currency": "SGD"
}
I also created a custom action under the Actions > Library, which the Trigger set to Login / Post Login.
Below is the code that I added to the action.
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
const { base_currency } = event.user.user_metadata;
api.idToken.setCustomClaim(`${namespace}/base_currency`, base_currency);
};
Lastly, I added the custom action to the Trigger, post-login
under the Actions > Triggers.
I login to the application and to verify the details if the base_currency
is added to the idToken
.
const session = await auth0.getSession();
console.log(session);
Below is the output that I’m receiving from the getSession()
method.
{
"user": {
"given_name": "",
"family_name": "",
"nickname": "",
"name": "",
"picture": "",
"email": "",
"email_verified": ,
"sub": ""
},
"tokenSet": {
"accessToken": "",
"scope": "",
"refreshToken": "",
"expiresAt": 1739245169
},
"internal": {
"sid": "",
"createdAt": 1739158769
}
}