User metadata as well as App metadata is not showing as part of acess token while using Action Library

Hi,
I tried to fetch user metadata as well as app metadata as part of access token Using Actions Library options. I tried in rules its working fine, but In case Of the Action it’s not working. Can anyone suggest the solution? Is there anything I need to enable it? Refer the sample code attached it. I have referred the code from this link

exports.onExecutePostLogin = async (event, api) => {
	const userEmail = event.user.email;
	const userId = event.user.user_id;

	// This property will never be undefined in Actions.
	const userAppMetadata = event.user.app_metadata;

	// ... additional code
};

Hi @selvi,

This line of code const userAppMetadata = event.user.app_metadata; is used to get the user’s current app_metadata information.

If you need to include the user_metadata and app_metadata in your access token, you would need to add them as a custom claim.

exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
if (event.authorization) {
    // Set claims in access token
    api.accessToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
    api.accessToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
  }
};

(Reference: Adding custom claims to tokens)

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.