headplane/app/utils/sessions.ts

37 lines
670 B
TypeScript
Raw Normal View History

2024-03-25 17:51:11 -04:00
import { createCookieSessionStorage } from '@remix-run/node' // Or cloudflare/deno
type SessionData = {
hsApiKey: string;
authState: string;
authNonce: string;
authVerifier: string;
2024-03-30 02:44:06 -04:00
user: {
name: string;
email?: string;
};
2024-03-25 17:51:11 -04:00
}
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',
2024-03-30 02:44:06 -04:00
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2024-03-25 17:51:11 -04:00
secrets: [process.env.COOKIE_SECRET!],
secure: true
}
}
)