Can you access user app_metadata from the front end with next.js?

Hey there @thekoala, bravo! :clap: :clap: Thanks a bunch for sharing this with the community :slight_smile:

I’ll add some color to this by sharing the following doc which outlines how metadata works in user profiles:

In addition to the Management API, you can also access user metadata via the /user
info
endpoint (need the user’s access token), as well as via custom claims in the user id and/or access token. For example, here’s an action that will add both user_metadata and app_metadata to the user’s id token which can be extracted by your app post login:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
    api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.client.metadata);
  }
};

Thanks again for your engagement with this, I’m sure it will be beneficial to other users :metal:

Cheers!

4 Likes