kinde-oss/kinde-auth-nextjs

Documentation issue: (How to get specific user roles by their id)

rasel-stacklearner opened this issue · 1 comments

Prerequisites

How can we improve the docs or what is missing?

I am using Kinde with a Next.js application. In my business login, I would like to retrieve user roles based on the user's ID. I am currently using the "createKindeManagementAPIClient" but it doesn't have a method to fetch the specific user roles. Furthermore, the access_token does not contain the roles information. Could you kindly assist me in retrieving the roles of a specific user?
Thanks.

Provide extra context, such as what you were trying to do and your requirements

I am using Kinde with a Next.js application. In my business login, I would like to retrieve user roles based on the user's ID. I am currently using the "createKindeManagementAPIClient" but it doesn't have a method to fetch the specific user roles. Furthermore, the access_token does not contain the roles information. Could you kindly assist me in retrieving the roles of a specific user?
codes:

const enforceUserIsAuthenticated = t.middleware(async ({ ctx, next }) => {
  const {usersApi, rolesApi} = await createKindeManagementAPIClient();

  
  const { isAuthenticated, email, userId } = ctx.session!;

  console.log("[protected Procedure", await usersApi.getUsers({userId}));
  console.log("[protected Procedure", await rolesApi.getRoles({
  }));


  if (!isAuthenticated || !email || !userId) {
    throw new TRPCError({ code: "UNAUTHORIZED" });
  }
  return next({
    ctx,
  });
});

If the docs page already exists, please provide a link

No response

@rasel-stacklearner You can get the users roles using the organization user role

https://kinde.com/api/docs/#list-organization-user-roles

This is under the organizationApi, this is because users role can vary between organisations.