Welcome to the Kinde community.

A
A
A
M
T
Members
Sophia
S
Sophia
Offline, last seen 3 weeks ago
Joined September 23, 2024
Hi there, I've been trying to work out a solution to an issue with my auth flow for a while and thought I had it but having more issues.

I'm using tRPC in a Next.js full stack app and have updated my user's permissions via the Kinde API. Now I'm trying to get those updated permissions to take effect in my app, without logging out and logging in again. They're definitely working in the Kinde UI.

The component I want to see them updated in is a client component.
I've tried making calls to my tRPC API methods, which then contain a call to refreshTokens() from getKindeServerSession(). NB - all other methods from getKindeServerSession() work fine in my tRPC files. However, no matter what, the permissions aren't returning correctly.

Here's a snippet from my auth-callback function where I initially update the org & permissions:

await fetch("https://kettleon.kinde.com/api/v1/organizations/${newOrgCode}/users", { method: 'POST', body: JSON.stringify(userInputBody), headers: headers }) .then(function (res) { return res.json(); }); organisation = newOrgCode } const { refreshTokens } = getKindeServerSession(); await refreshTokens();


And here's a specific refresh function I tried as well:

refreshUser: privateProcedure.query(async ({ ctx, input }) => { const { refreshTokens } = getKindeServerSession() const tokens = (await refreshTokens()) as { accessToken: string, refreshToken: string }; console.log(tokens) const{ getPermissions } = getKindeServerSession() const permissions = (await getPermissions()) as KindePermissions | null; console.log(permissions) // returns {permissions: [], orgCode: null} return { data: permissions?.permissions, status: 200, success: true }; }),

Neither seems to work 😦 any help very much appreciated
13 comments
O
p
S
Hi there,

I've got a NextJS app using the SDK and also the Kinde API on other sections. Basically I want the user flow to be:

A manager-level user registers (using the <RegisterLink> component), creating a new organisation and then is able to add their team members to that organisation from within the app using the Kinde API.

I've got this working but have noticed a bug I'm not sure if there's a solution for.

My <RegisterLink> passes the create_new_org property so as long as it's clicked, it's fine.

However, if a new user clicks "Sign In" by accident, they're taken to a Kinde sign-in screen, which has the option "no account? create one". If they click this link, it registers them, without creating a new org, so they get added to the default org, which messes up the above user flow.

Is there any way to remove this "create one" link from the Kinde sign-in page? Or, any way to pass the create_new_org property to it? Or am I going to have to uproot the whole thing and use custom sign-in and register pages?

If the third option, is it possible to use the NextJS SDK components <LoginLink> and <RegisterLink> with custom sign-in pages? Otherwise could you point me to the best way to implement this in NextJS?

Thank you very much in advance!
4 comments
S
P
Hi there! Super new to Kinde and web development in general so apologies for my lack of knowledge in advance.

I'm trying to do something that I hope can be done via Kinde but I'm not 100% sure - I'd like for a logged in user with a specific role (ie a manager) to be able to add users to Kinde (within their organisation) via our site using the Kinde API.

Our app is full-stack NextJS using app routing with TypeScript, so I looked through the NextJS SDK documentation. I first got very stuck looking at the code snippets there as I couldn't find any documentation for how to use the API with createKindeManagementAPIClient especially trying to use the createUser method on the usersApi.

I then tried to just use fetch() using the code samples on the API docs themselves, but had issues with the access token. I've tried to obtain the access token via Postman which worked fine, so I think my setup on Kinde is correct, but for some reason the client authentication fails when I try to run it locally in my code.

Could this be because I'm using http://localhost:3000 for testing? I've tried setting the "audience" parameter to this URL to see if this resolves it.

I'll follow up with a comment containing the code I've currently got in my component where I'm trying to add users.
The env variables are the ones for my M2M application in Kinde. I've switched the API on for this application.

It's currently not getting to the addUser() function because the accessToken is coming back undefined because the client authentication isn't working.

Any ideas as to why this could be? Is it the domain or have I missed something else?

Thank you in advance ❤️
10 comments
O
S