Post-Login Action: Unable to read metadata

In the old version of rules I was able to add user/app metadata upon login:

function (user, context, callback) {
  const namespace = 'https://example.com';
  user.user_metadata = user.user_metadata || {};
  user.app_metadata  = user.app_metadata || {};
  context.idToken[namespace + "user_metadata"] = user.user_metadata;
  context.idToken[namespace + "app_metadata"]  = user.app_metadata;

  return callback(null, user, context);
}

I’m trying to follow the preferred method of using actions, but I’m unable to see anything in my user object. I’m using the @auth0/auth0-react library, specifically useAuth0() function.

Things I’ve tried:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://example.com;
  api.accessToken.setCustomClaim(`${namespace}/testA`, 'Sample Value');
  api.idToken.setCustomClaim(`${namespace}/testB`, 'Sample Value');
  api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
  api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.app_metadata);
};

Then I am trying to access it with the following:
const { user } = useAuth0();

But no additional info comes into the user object.

How can I do this with actions? Or do I need to continue to use rules?

Hi @lorkel,

It looks like you are missing a single quote on your namespace string. Could this be the issue?

const namespace = 'https://example.com;

Should be:

const namespace = 'https://example.com';