Getting user_metadata in @auth0/nextjs-auth0


I’m using @auth0/nextjs-auth0 and useUser() to get the logged in user on my site. Works fine. However, I’m trying to read the users user_metadata, but I cannot make it work.

If I understand things correctly I need to attach that info myself in a “custom Action” and add it to a flow. I’ve tried, but no extra information comes out. All guides out there seems to use some outdated method of retrieving data.

I have a custom action called upon login that does something like:

  api.idToken[''] = {hi: "there"};

Tried lots of different variations, but docs doesn’t mention this? Only how to ADD metadata when logging in, which worked for me as well. Starting to question if this is even possible nowadays?


Suddenly it just worked… not sure what I did wrong previosly. Strange. Anyway, for others with the same issue, this worked:

exports.onExecutePostLogin = async (event, api) => {
  const userMetadata = event.user.user_metadata;
  api.idToken.setCustomClaim("user_metadata", userMetadata)