undefined access_token when using session manager with typescript SDK

Hi all! I'm having trouble calling my API in a NextJS Hono server monorepo. I'm wanting to call an API and check for auth but eaverytime I do my server throws a 500 as the access_token from Kinde is undefined in the session manager. Here is my session manager code:
export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getting session item", key, result);
return result;
},
async setSessionItem(key: string, value: unknown) {
console.log("setting session item", key, value);
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
console.log("removing session item", key);
deleteCookie(c, key);
},
async destroySession() {
console.log("destroying session");
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});
export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getting session item", key, result);
return result;
},
async setSessionItem(key: string, value: unknown) {
console.log("setting session item", key, value);
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
console.log("removing session item", key);
deleteCookie(c, key);
},
async destroySession() {
console.log("destroying session");
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});
when I console log the getCookie result I get an undefined, but it is defined when setting it. Not sure if my implementation is correct or not. Any help is appreciated. Thanks.
4 Replies
Shampurrrs
ShampurrrsOP3mo ago
yeah! Unfortunately I'm going to have to move away from Kinde as it is too faulty and teh support is lacking. Thanks for your reply though.
CB_Kinde
CB_Kinde3mo ago
Hi @Shampurrrs Sorry to hear you've had issues. We would welcome specific feedback about your experience and how we could improve it. We pride ourselves on offering pretty great support to paid AND free plan customers, so would be great undeerstand where we let you down.
Shampurrrs
ShampurrrsOP3mo ago
Hi! It's just the generic responses that mimic the documentation I have looked at, it's telling me things I already know and it feels like i't not worth the time to give support. Too be fair I am using a free plan currently and I am not a very good dev, so maybe it isn't worth supports time. Cheers. Hi Sam. if I run this code where I am logging the result of the session. my session is undefined, then has a result then becomes undefined again.
getSessionItem undefined
getSessionItem 95b005908e6beb10ddc10e51628e
getSessionItem undefined
getSessionItem undefined
getSessionItem 95b005908e6beb10ddc10e51628e
getSessionItem undefined
I am using Hono for the cookie functions, maybe Kinde is just not meant to work with Hono?
export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getSessionItem", result);
return result;
},
async setSessionItem(key: string, value: unknown) {
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
deleteCookie(c, key);
},
async destroySession() {
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});
export const sessionManager = (c: Context): SessionManager => ({
async getSessionItem(key: string) {
const result = getCookie(c, key);
console.log("getSessionItem", result);
return result;
},
async setSessionItem(key: string, value: unknown) {
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
async removeSessionItem(key: string) {
deleteCookie(c, key);
},
async destroySession() {
["id_token", "access_token", "user", "refresh_token"].forEach((key) => {
deleteCookie(c, key);
});
},
});
CB_Kinde
CB_Kinde3mo ago
Thanks for adding that info - when you say "it" do you mean KindeAI? It is reading the docs and is trained to give responses from there. In all other channels, you'll get a human.

Did you find this page helpful?