How can i add user permissions to Id token?

Hi, I’m trying to add user permissions to my Id token to consume them later on the client side of my Next.js 14 based app, I successfully added roles to the Id token, However i’m having hard time including permissions as well, I took reference of following documentation and i also have attached the action code that i added from Auth0 dashboard, Any help would be greatly appreciated, thanks!

Link to documentation explaining user’s permssions:-

Get a User’s Permissions

My Actions Code:-

const axios = require('axios');

exports.onExecutePostLogin = async (event, api) => {

  let config = {
    method: 'get',
    maxBodyLength: Infinity,
    url: `https://login.auth0.com/api/v2/users/${event.user.user_id}/permissions`,
    headers: {
      'Accept': 'application/json'
    }
  };

  axios.request(config)
    .then((response) => {
      console.log("====> Auth Data", JSON.stringify(response.data));

	// Not sure what needs to be done here in order to receive it as a field inside token
      api.idToken.setCustomClaim(`${namespace}/permissions`, JSON.stringify(response.data));
    })
    .catch((error) => {
      console.log(error);
    });
};

I also tried to console inside my action code and later checked it from monitoring tab to see if log is there but nothing got printed there as well.

Also is this recommended way to work with permissions? My primary requirement is to load a specific piece of UI based on whether the user has right permissions or not.

Hi @rutwik246,

Welcome to the Auth0 Community!

You can find the solution to your issue by following the steps in the following Knowledge Solution: How to Add Roles and Permissions to the ID Token Using Actions. All Knowledge Solutions posts have been validated by a team of Auth0 technical reviewers, so you can be confident in the technical accuracy of the content. Please let me know if you have any additional questions or concerns!

Thanks
Dawid

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.