Files
documenso/packages/auth/server/lib/session/session-cookies.ts
David Nguyen e20cb7e179 fix: wip
2025-01-31 23:17:50 +11:00

35 lines
968 B
TypeScript

import type { Context } from 'hono';
import { getSignedCookie, setSignedCookie } from 'hono/cookie';
import { authDebugger } from '../utils/debugger';
/**
* Get the session cookie attached to the request headers.
*
* @param c - The Hono context.
*/
export const getSessionCookie = async (c: Context) => {
const sessionId = await getSignedCookie(c, 'secret', 'sessionId'); // Todo: Use secret
return sessionId;
};
/**
* Set the session cookie into the Hono context.
*
* @param c - The Hono context.
* @param sessionToken - The session token to set.
*/
export const setSessionCookie = async (c: Context, sessionToken: string) => {
await setSignedCookie(c, 'sessionId', sessionToken, 'secret', {
path: '/',
// sameSite: '', // whats the default? we need to change this for embed right?
// secure: true,
domain: 'localhost', // todo
}).catch((err) => {
authDebugger(`Error setting signed cookie: ${err}`);
throw err;
});
};