Welcome to the Kinde community.

P
K
A
A
A

Updated User Permissions and Roles Not Reflecting After API Call

Hey Guys i updated some permissions and roles for a user and then hit this api
https://kinde.com/api/docs/#refresh-user-claims-and-invalidate-cache
and got
{
"code": "CLAIMS_REFRESH_SUCCESS",
"message": "Claims successfully refreshed"
}
to see if he gets updated without logging out and in again but it didn't work
need help to do it please

2
E
A
A
23 comments

hi , the refreshed claims will be available after the token is exchanged via the refresh token flow. You need to request the offline scope when starting the auth flow, which will generate a refresh token alongside the access token. You could use the refresh token to generate an updated tokens after the refresh clams.

I see we need to document this flow better.

Hello
my main goal now is to make all users to get new token
cz i added some permissions to them


how can i force user to login again ?
i tried to suspend them but they can still work until they logout

If you didn't start the offline session, another method is starting an auth flow without providing any prompt, this way the user will be redirected to Kinde and back, and will receive the updated token.

In case their auth session expired, they will be asked to authenticate, for the already authenticated session the process only involves several redirects and no UI.


can you please share me documentation about it

because i need to do this on production and i can't make mistakes 😅

this needs time to implement is there any faster method?

easier way i need to kick all users out from the system how to do it ?

Your users already have live access tokens which are not connected to Kinde any longer in any way until the token expired.

You need the app to make a request to start the auth flow from your code. With the refresh tokens this would have happened on the page refresh automatically, but without it implemented I can't see a fast method so far.

Which SDK are you using?

let me chat with the team, so far I can't think of an easy fix

just an update, we are still looking into an alternative solution for you.

Hello
thank you sir

, in the Next.js SDK you can refresh tokens by calling:

const session = await getKindeServerSession();
await session.refreshTokens();
The best I can figure is after you’ve made the broad permission changes, deploy your app with this call in a common route conditionally (not recommended to call this frequently as it adds request overhead).

Does this help for your case?

Hello
gonna try it and get back to you
thanks

Hello
i tried it and its look like not working !

, can you provide some details about what you have tried? Are you calling refreshTokens() from middleware?

actually i'm trying to refresh token for the user once he changes a permission to himself
so basically i'm doing it in a api route

, the call to const newTokens = await refreshTokens(); should return new tokens, can you see if there are new tokens returned? If you are getting null returned can you set the environment variable KINDE_DEBUG_MODE=true and see if there are any errors logged?


KINDE_DEBUG_MODE=trueis already on but no error are being logged in console and it is returning null
newTokens null

hey , if you are calling refreshTokens in the context of a Nextjs page, unfortunately, we can’t update the cookies from there which sucks.

So you might have to put the refreshTokens part into a sever action in which case the newTokens should return new tokens and update the permissions.

If the permissions are not updating then it is most likely a cache invalidation thing on our part!!

Add a reply
Sign up and join the conversation on Slack
Join