How to get role from user data on login

System Information
  • Strapi Version: 4.1.11
  • Operating System: Windows 11
  • Database: Postgress
  • Node Version: 16.13.1
  • NPM Version: 8.1.2
  • Yarn Version:

I am using the default login of strapi /api/auth/local. It returns jwt and user data, I added role in the User table and also asigned role to the user, but i am not getting rol in user data.

I want to get the role of user on login, any method to populate the response with role or get role details from the jwt itself!

I was facing the same issue. I could solve it by extending the auth controller of the users-permissions plugin. strapi/auth.js at master · strapi/strapi · GitHub

You need to copy the whole callback function to /src/extensions/users-permissions/strapi-server.js and change line 59 to include your fields you want to populate:

const user = await strapi.query('plugin::users-permissions.user').findOne({ where: query, populate: ["role", "profile_picture"]});
1 Like

Thanks for your response, I had also found the same solution and it works perfectly!

How can we edit the user controller it is located in a node_modules.