Hello Team. I am having issues getting roles for users. I have setup the roles and the permissions.
I am using NextJS App Router and everything works exactly perfectly. When i call getUser
i have all details and getPermissions
but getRoles
returns null even though roles are setup
Hi here's a few troubleshooting tips:
1. Role Configuration: Ensure that the roles are correctly configured in your Kinde account. Double-check that the roles are assigned to the user you are testing with.
2. API Call: Verify that the API call to fetch roles is correctly implemented. Sometimes, the issue might be with how the data is being fetched or processed.
3. Session Data: Make sure that the session data includes roles. You can log the session data to see if roles are being included.
Here is a basic example of how to fetch roles using getKindeServerSession
:
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server"; export default async function Home() { const { getRoles } = getKindeServerSession(); const roles = await getRoles(); console.log(roles); // This should log the roles if they are correctly set up return ( <div> <h1>User Roles</h1> <pre>{JSON.stringify(roles, null, 2)}</pre> </div> ); }Let me know if this helps or if you need further assistance.
The code sample is for Next.js. Let us know if you need an example for a different framework.
user: publicProcedure.query(async () => { const { getUser, isAuthenticated, getPermissions, getRoles, getOrganization } = getKindeServerSession(); const { user, roles, permissions, organization, authenticated } = await props({ user: getUser(), roles: getRoles(), permissions: getPermissions(), organization: getOrganization(), authenticated: isAuthenticated() }); const tier = getTierNameFromRoles(permissions?.permissions ?? []); return { tier, user, roles, authenticated, permissions, organization }; }) };
Hi there. Not to worry, we can look into this for you. Can you tell me your kinde business / kinde domain?
Also i don't know if this is related but i am connecting to the management API using the typescript sdk and when i get a user the default organization is not even set on them
Hey ,
You are right. Roles and permissions are unique per user.
Are you would check that in your Kinde Settings > Application > Tokens >AccessToken > Roles are switched on?
Also i don't know if this is related but i am connecting to the management API using the typescript sdk and when i get a user the default organization is not even set on themIs the
Add users to the default organization if no organization is specified
toggle (under Settings > Environment > Details) turned on?Are you would check that in your Kinde Settings > Application > Tokens >AccessToken > Roles are switched on?haaaa it looks like the Toggles in settings were not switched on
Hey ,
Thanks for getting back to me.
After enabling the toggle to add roles to the access token, is getRoles
still returning null?