kinde-oss / kinde-auth-nextjs

Kinde NextJS SDK - authentication for server rendered apps
https://kinde.com/docs/developer-tools/nextjs-sdk/
MIT License
132 stars 17 forks source link

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

Closed rasel-stacklearner closed 2 months ago

rasel-stacklearner commented 3 months ago

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

DanielRivers commented 3 months ago

@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.