headplane/app/utils/sessions.ts

30 lines
635 B
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { createCookieSessionStorage } from 'react-router'; // Or cloudflare/deno
2024-03-25 17:51:11 -04:00
export type SessionData = {
2024-03-25 17:51:11 -04:00
hsApiKey: string;
authState: string;
authNonce: string;
authVerifier: string;
2024-03-30 02:44:06 -04:00
user: {
name: string;
email?: string;
};
2024-12-31 10:30:14 +05:30
};
2024-03-25 17:51:11 -04:00
type SessionFlashData = {
error: string;
2024-12-31 10:30:14 +05:30
};
2024-03-25 17:51:11 -04:00
2024-12-31 10:30:14 +05:30
export const { getSession, commitSession, destroySession } =
createCookieSessionStorage<SessionData, SessionFlashData>({
2024-03-25 17:51:11 -04:00
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',
2024-12-31 10:30:14 +05:30
},
});