I am writing a custom action to set an extra field in a user’s ID token when logging in to my react application called role, and the value that it is always being set to is “Provider”. Here is my current code in the action for auth0:
/**
- Handler that will be called during the execution of a PostLogin flow.
- @param {Event} event - Details about the user and the context in which they are logging in.
- @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const namespace = ‘https://myapp.example.com’;
const { favorite_color, preferred_contact } = event.user.user_metadata;if (event.authorization) {
// Set claims
api.idToken.setCustomClaim(role
, “Provider”);
}
};
/**
- Handler that will be invoked when this action is resuming after an external redirect. If your
- onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
- @param {Event} event - Details about the user and the context in which they are logging in.
- @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };
How can I change the “Provider” part in this line" api.idToken.setCustomClaim(role
, “Provider”);
to be the user’s current role?