Get current user role

Hello! Im using NextJS 15 with Kinde auth (love it so far) I have been looking through older posts about how to get the current users role, but I have not yet succeeded to find a solution. My goal is to get the role when fetching "getUser" through "getKindeServerSession". I have made sure to create desired roles and assigned them. Maybe i have not really understood the concept of how to use roles properly in Kinde Auth, im currently studying front-end dev so sorry if the answer is rather simple πŸ™‚ Thanks in advance! EDIT / ADDITION: While reading the documentation i see that Kinde recommend controlling access to features on permission-level -> We recommend you use permissions for controlling access to features within your application, then use roles to group the permissions. But for interest i still would like to know if above is possible.
4 Replies
Yoshify
Yoshifyβ€’3w ago
Hello to you! You can absolutely access roles - you'll just need to make a configuration change. In your Kinde Application (on the Dashboard) click Tokens on the left, scroll down to Token customization and click customize on Access Token. Enable "Roles (array)" and click save. Now to access the roles in your code, you can use getAccessToken returned from getKindeServerSession. This will include the users roles in an array that looks like so:
"roles": [
{
"id": "018ee9aa-f92b-83fc-1d40-1234567890",
"key": "admin",
"name": "Admin"
}
],
"roles": [
{
"id": "018ee9aa-f92b-83fc-1d40-1234567890",
"key": "admin",
"name": "Admin"
}
],
I've attached some images to help direct you. Hope this helps!
No description
No description
No description
moggelitalanya
moggelitalanyaOPβ€’3w ago
Thank you so much, I never considered to use the access token like this , focusing so hard on the USER object . Thank you again , I will try this ASAP πŸ€—
Yoshify
Yoshifyβ€’3w ago
Glad to hear it! Let me know how you get on πŸ™‚
moggelitalanya
moggelitalanyaOPβ€’3w ago
Works like a charm, thank you very much πŸ™‚
Want results from more Discord servers?
Add your server