Retrieving app_metadata section from the user once logged in

Hey there @rosario.martone.uk welcome to the community!

The most effective way is probably to add the metadata to tokens and go about it that way - You need to add the metadata as a custom claim(s) using an action:

An example might look like:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
  const { favorite_color, preferred_contact } = event.user.user_metadata;

  if (event.authorization) {
    // Set claims 
    api.idToken.setCustomClaim(`${namespace}/favorite_color`, favorite_color);
    api.idToken.setCustomClaim(`${namespace}/preferred_contact`, preferred_contact);
  }
};
1 Like