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

Commit 193943d

Browse files
HasithDeAlwisMFarabi619
authored andcommitted
feat(portal): save userId in session after successful login
1 parent 5c2f16c commit 193943d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

apps/portal/app/routes/login.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import type { LoaderFunction } from '@remix-run/node'
33
import { Login as LoginPage } from '@cuhacking/portal/pages/login'
44
import { redirect } from '@remix-run/node'
5+
import { commitSession, getSession } from '../sessions'
56

67
export const loader: LoaderFunction = async ({ request }) => {
78
const cookie = request.headers.get('Cookie')
89

910
try {
10-
const res = await fetch(`${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_PORTAL_LOCAL_URL : process.env.CUHACKING_2025_PORTAL_PUBLIC_URL}/api/users/me`, {
11+
const res = await fetch(`${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}/api/users/me`, {
1112
headers: { Cookie: cookie || '' },
1213
})
1314

@@ -17,8 +18,16 @@ export const loader: LoaderFunction = async ({ request }) => {
1718

1819
const data = await res.json()
1920

21+
const session = await getSession(cookie)
22+
session.set('userId', data.user.id)
23+
const newCookie = await commitSession(session)
24+
2025
if (data?.user) {
21-
return redirect('/dashboard')
26+
return redirect('/', {
27+
headers: {
28+
'Set-Cookie': newCookie || '',
29+
},
30+
})
2231
}
2332
}
2433
catch (error) {

0 commit comments

Comments
 (0)