Sophia
Explore posts from serversKKinde
•Created by Sophia on 5/21/2024 in #💻┃support
How to refresh tokens in a Next.js client component?
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 appreciated14 replies
KKinde
•Created by Sophia on 5/6/2024 in #💻┃support
Kinde sign-in screen register link means no new org
5 replies
KKinde
•Created by Sophia on 3/6/2024 in #💻┃support
Creating users via Kinde API
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 ❤️
11 replies