kinde-oss / kinde-auth-nextjs

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

Bug: cannot retrieve organization details #201

Open dam6pl opened 3 months ago

dam6pl commented 3 months ago

Prerequisites

Describe the issue

I'm logging in to the organization but cannot retrieve these data in NextJS. I'm unable to get these details by using the following code in the main Layout.ts file.

const kinde = getKindeServerSession();
const userOrganizations = await kinde.getUserOrganizations();
console.log(userOrganizations); // { orgCodes: [], orgs: undefined }

ID token returns the following data:

console.log(await kinde.getIdToken());
// {
//   ...
//   sub: 'kp_d56abde76a3044509cfc3fb0113639a7',
//   'x-hasura-ext-provider': {},
//   'x-hasura-org-codes': [ 'org_2fb99a3e2a5' ],
//   'x-hasura-organizations': [ { id: 'org_2fb99a3e2a5', name: 'docker' } ]
// }

Let me know if you need anything else from my side. This is quite an important issue for me, as it blocks my development. Thanks for your support!

Library URL

https://github.com/kinde-oss/kinde-auth-nextjs/

Library version

2.3.6

Operating system(s)

macOS

Operating system version(s)

14.6.1

Further environment details

No response

Reproducible test case URL

No response

Additional information

No response

peterphanouvong commented 3 months ago

Thanks @dam6pl, this is a bug - we'll fix this for you asap

peterphanouvong commented 3 months ago

In the meantime would you be able to grab the orgs from the idToken / using the getClaim helper

peterphanouvong commented 3 months ago

Just double checking that you have enabled Hasura mapping intentionally.

We will have to support the hasura mappings in the SDK :) I am working on it now

image
dam6pl commented 2 months ago

Hey @peterphanouvong, I checked the fix, but not sure if the issue has been fully resolved. Please take a look at the details below. When I try to get user organizations I get nothing.

const organizations = await kinde.getUserOrganizations();
console.log(organizations); // null

But, when I check the ID token, I can see organizations.

console.log(await kinde.getIdToken());
// {
//   ...
//   sub: 'kp_b224d812a8db41e4826d1cd376097c8c',
//   x-hasura-ext-provider: {},
//   x-hasura-org-codes: [ 'org_e7b4dc67239e', 'org_934cf51676099' ],
//   x-hasura-organizations: [
//     { id: 'org_e7b4dc67239e', name: 'Test DN' },
//     { id: 'org_934cf51676099', name: 'dntest' }
//   ]
// }

Can you suggest if I'm doing something wrong, please? Thanks!

peterphanouvong commented 2 months ago

Hey @dam6pl you're not doing anything wrong! I haven't yet pushed a fix just yet, are you able to grab the information you need by taking from the IdToken instead of using the getUserOrganizations helper for now?

We're preparing a more substantial fix to support hasura mappings :)

leonardocintra commented 1 month ago

I have a same problem... waiting fix getUserOrganization.

I am working with sdk nextjs 14.x

tymkiwdylan commented 1 week ago

How is this going? I have the same problem, but I do not have Hasura Mapping enabled.