Strapi Version: 4.0.0
Operating System: MacOS
Node Version: 16.13.1
When logging in as a User using the ‘/auth/local’ call. Is it possible to also return the Role of that given user?
When you login with a user you will get a token back. You can then use the token and make a call to
/users/me and it will give the role back in that response. It’s an extra call but saves you from modifying the auth local login provider etc.
In the response you can do
response.role.name to get the name of the role it’s an object looking like this
Tried that, a call to api/users/me with the bearer token returns the user data and not the role of the user. What can I do about that?
Same here I made sure to give the role permissions to find and findOne role too. Doesn’t seem like the /me endpoint returns that data.
Since Strapi version 4.2.2 the route
api/users/me no longer returns the role field in the user data but accepts populating (see https://github.com/strapi/strapi/issues/13296).
So now to get the user’s role you need to populate the role field, thus the call will be
Note that you also need to give the role permissions to find role too.
Add the ‘populate’ query like this: /api/users/me?populate=* This will return everything including the role of the user.
thanks man that’s work fine
Dont forget to allow role in perms:
Otherwise you will not see roles, even with populate.