Welcome to the Kinde community

Updated yesterday

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:
Plain Text
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.
S
S
C
3 comments
While I can see an example of a session manager implementation in TypeScript, the documentation doesn't specifically cover integration with Hono. The closest example shown is a basic in-memory session manager:

Plain Text
let store: Record<string, unknown> = {};

const sessionManager: SessionManager = {
   async getSessionItem(key: string) {
   return store[key];
   },
   async setSessionItem(key: string, value: unknown) {
   store[key] = value;
   },
   async removeSessionItem(key: string) {
   delete store[key];
   },
   async destroySession() {
   store = {};
   }
  };



The documentation notes that this implementation would only work for a single user in local development, and that production environments need a more robust solution. It mentions that "The appropriate session store for your application will depend on your application architecture, for example encrypted cookies in a stateless server environment or a shared cache/database for a load balanced cluster of servers."
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.
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.
Add a reply
Sign up and join the conversation on Discord