How to include user_metadata and app_metadata in user payload after login?

I’m attempting to do something that seems very trivial but having no luck with anything from the documentation.

Use Case:
I am using Nuxt and their Auth0 module and after logging in as a user I can get a user object like this:

      "email": "",
      "email_verified": true,
      "name": "",
      "nickname": "",
      "picture": "",
      "sub": "",

But what I’m looking to add to that payload is

    "app_metadata": "",
    "user_metadata": ""

I’m not seeing any Rule example or any toggles in the admin UI that simply say, include app_metadata and user_metadata with a users authenticated payload.

I have figured it out for anyone else that may want an easy way to just include all app_metadata and user_metadata in the user payload.

Add a rule like this, just update the namespace url (it doesn’t need to actually point to a live URL) :

function (user, context, callback) {
  var namespace = "";
  context.idToken[namespace + "appMetadata"] = user.app_metadata || {};
  context.idToken[namespace + "userMetadata"] = user.user_metadata || {};
  callback(null, user, context);
1 Like

Glad you have figured it out and thanks for sharing with the rest of community!