30 lines
635 B
TypeScript
30 lines
635 B
TypeScript
import { createCookieSessionStorage } from 'react-router'; // Or cloudflare/deno
|
|
|
|
export type SessionData = {
|
|
hsApiKey: string;
|
|
authState: string;
|
|
authNonce: string;
|
|
authVerifier: string;
|
|
user: {
|
|
name: string;
|
|
email?: string;
|
|
};
|
|
};
|
|
|
|
type SessionFlashData = {
|
|
error: string;
|
|
};
|
|
|
|
export const { getSession, commitSession, destroySession } =
|
|
createCookieSessionStorage<SessionData, SessionFlashData>({
|
|
cookie: {
|
|
name: 'hp_sess',
|
|
httpOnly: true,
|
|
maxAge: 60 * 60 * 24, // 24 hours
|
|
path: '/',
|
|
sameSite: 'lax',
|
|
secrets: [process.env.COOKIE_SECRET!],
|
|
secure: process.env.COOKIE_SECURE !== 'false',
|
|
},
|
|
});
|