Custom Claims working with idToken in Rules, but not in Actions

This rule works and custom claims are set to idToken

function (user, context, callback) {
  var namespace = "https://schemas.ysera.com/";
  user.user_metadata = user.user_metadata || {};
  context.idToken[namespace + "user_metadata"] = user.user_metadata; 
  callback(null, user, context);
}

but once I migrated to Action, this custom claim stopped working

exports.onExecutePostLogin = async (event, api) => {
	const namespace = "https://schemas.ysera.com/";
	api.idToken.setCustomClaim(`${namespace}user_metadata`, event.user.user_metadata || {});  
	return;
};

Anyone sees as to why Action doesnt work? As soon as I enable the Rule my login flow works. Action doesn’t.

Hey there @Dev_User welcome to the community!

I would try introducing an if statement like the following:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://schemas.ysera.com/";

  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}user_metadata`, event.user.user_metadata || {});
  }
};

1 Like

Thank you, but that didn’t help.

Is there an empty custom claim in the ID token with your namespace or is there nothing at all?