Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit 5c2f16c

Browse files
HasithDeAlwisMFarabi619
authored andcommitted
feat(portal): add utility to manage session data
1 parent c8c4d08 commit 5c2f16c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

apps/portal/app/sessions.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import process from 'node:process'
2+
import { createCookieSessionStorage } from '@remix-run/node'
3+
4+
const sessionSecret = process.env.SESSION_SECRET
5+
if (!sessionSecret) {
6+
throw new Error('SESSION_SECRET must be set')
7+
}
8+
9+
interface SessionData {
10+
userId: string
11+
}
12+
13+
interface SessionFlashData {
14+
error: string
15+
}
16+
17+
const { getSession, commitSession, destroySession }
18+
= createCookieSessionStorage<SessionData, SessionFlashData>(
19+
{
20+
cookie: {
21+
name: '__session',
22+
secure: process.env.NODE_ENV === 'production',
23+
secrets: [sessionSecret],
24+
sameSite: 'lax',
25+
path: '/',
26+
httpOnly: true,
27+
},
28+
},
29+
)
30+
31+
export { commitSession, destroySession, getSession }

0 commit comments

Comments
 (0)