j
j
Explore posts from servers
KKinde
Created by j on 4/23/2025 in #💻┃support
How does refresh token actually work?
yes working example would be awesome. i dont understand the last "getToken()" call – should that happen client side? or server side? How would we access the access token if you are in a serversided rendering call, and the token is expired, but we need to fetch some protected API endpoints with a refreshed token?
8 replies
KKinde
Created by j on 4/23/2025 in #💻┃support
How does refresh token actually work?
export async function loader({ request }: LoaderFunctionArgs) {
let user: User | null = null;

// calls kinde's getToken() under the hood
const authToken = await getAuthToken(request);
if (authToken) {
const meResponse = await getMe(request);
if (!meResponse.successData) {
// Throw an error to be caught by the ErrorBoundary
throw new Error("Failed to fetch user data.");
}
user = meResponse.successData;
}


return data(
{
user,
publicEnv: getPublicEnvFromServer(),
},
{
// returns { headers } = getKindeSession(request)
headers: await getAuthHeaders(request),
}
);
}
export async function loader({ request }: LoaderFunctionArgs) {
let user: User | null = null;

// calls kinde's getToken() under the hood
const authToken = await getAuthToken(request);
if (authToken) {
const meResponse = await getMe(request);
if (!meResponse.successData) {
// Throw an error to be caught by the ErrorBoundary
throw new Error("Failed to fetch user data.");
}
user = meResponse.successData;
}


return data(
{
user,
publicEnv: getPublicEnvFromServer(),
},
{
// returns { headers } = getKindeSession(request)
headers: await getAuthHeaders(request),
}
);
}
8 replies
KKinde
Created by j on 4/23/2025 in #💻┃support
How does refresh token actually work?
and i am calling this at the root loader and returning it via the response headers
8 replies
KKinde
Created by j on 4/23/2025 in #💻┃support
How does refresh token actually work?
i know for sure the token is truly expired when i was trying to refresh the token, but comparing the header's value vs current one, the values were the same
8 replies
TtRPC
Created by j on 2/20/2025 in #❓-help
best practice for invalidating protected queries upon profile switch
bump
3 replies