Skip to content

Commit 45dfd9b

Browse files
committed
fix(portal): auth not working due to env vars not loading in values
1 parent 860a50a commit 45dfd9b

File tree

9 files changed

+89
-14
lines changed

9 files changed

+89
-14
lines changed

apps/portal/app/routes/_index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { redirect } from '@remix-run/node'
55

66
export const loader: LoaderFunction = async ({ request }) => {
77
const cookie = request.headers.get('Cookie')
8+
const baseUrl
9+
= process.env.NODE_ENV === 'development'
10+
? 'http://localhost:8000'
11+
: 'https://axiom.cuhacking.ca'
812

913
try {
10-
const API_URL = `${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}`
14+
const API_URL = baseUrl
1115
const res = await fetch(`${API_URL}/api/users/me`, {
1216
headers: { Cookie: cookie || '' },
1317
})

apps/portal/app/routes/admin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { redirect } from '@remix-run/node'
55
export const loader: LoaderFunction = async () => {
66
const adminURL
77
= process.env.NODE_ENV === 'development'
8-
? `${process.env.CUHACKING_2025_AXIOM_LOCAL_URL}/admin`
9-
: `${process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}/admin`
8+
? `http://localhost:8000/admin`
9+
: `https://axiom.cuhacking.ca/admin`
1010

1111
return redirect(adminURL)
1212
}

apps/portal/app/routes/api.auth.tsx

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
11
/* eslint-disable node/prefer-global/process */
22
import type { LoaderFunction } from '@remix-run/node'
33
import { redirect } from '@remix-run/node'
4+
import { commitSession, getSession } from '../sessions' // Import session utilities
45

5-
export const loader: LoaderFunction = async () => {
6-
return redirect(`${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}/api/users/oauth/linkedin`)
7-
// HALP we need to log the user in and then set the session storage to save the userId
8-
/* return redirect('/login') */
6+
export const loader: LoaderFunction = async ({ request }) => {
7+
const baseUrl
8+
= process.env.NODE_ENV === 'development'
9+
? 'http://localhost:8000'
10+
: 'http://axiom.cuhacking.ca'
11+
12+
try {
13+
const authResponse = await fetch(`${baseUrl}/api/users/oauth/linkedin`, {
14+
method: 'POST',
15+
headers: {
16+
'Content-Type': 'application/json',
17+
},
18+
credentials: 'include',
19+
})
20+
21+
if (!authResponse.ok) {
22+
console.error('OAuth login failed:', authResponse.status, authResponse.statusText)
23+
return redirect('/login')
24+
}
25+
26+
const userResponse = await fetch(`${baseUrl}/api/users/me`, {
27+
method: 'GET',
28+
headers: {
29+
'Content-Type': 'application/json',
30+
},
31+
credentials: 'include',
32+
})
33+
34+
if (!userResponse.ok) {
35+
console.error('Failed to fetch user data:', userResponse.status, userResponse.statusText)
36+
return redirect('/login')
37+
}
38+
39+
const userData = await userResponse.json()
40+
const userId = userData?.id
41+
42+
if (!userId) {
43+
console.error('No userId returned from API')
44+
return redirect('/login')
45+
}
46+
47+
const session = await getSession(request.headers.get('Cookie'))
48+
session.set('userId', userId)
49+
50+
return redirect('/dashboard', {
51+
headers: {
52+
'Set-Cookie': await commitSession(session),
53+
},
54+
})
55+
}
56+
catch (error) {
57+
console.error('Error during OAuth login:', error)
58+
return redirect('/login')
59+
}
960
}
1061

1162
export default function AuthRedirect() {

apps/portal/app/routes/dashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const loader: LoaderFunction = async ({ request }) => {
3838
const cookie = request.headers.get('Cookie')
3939

4040
try {
41-
const API_URL = `${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}`
41+
const API_URL = `${process.env.NODE_ENV} === 'development' ? http://localhost:8000 : https://axiom.cuhacking.ca`
4242
const res = await fetch(`${API_URL}/api/users/me`, {
4343
headers: { Cookie: cookie || '' },
4444
})

apps/portal/app/routes/login.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import { commitSession, getSession } from '../sessions'
66

77
export const loader: LoaderFunction = async ({ request }) => {
88
const cookie = request.headers.get('Cookie')
9+
const baseUrl
10+
= process.env.NODE_ENV === 'development'
11+
? 'http://localhost:8000'
12+
: 'https://axiom.cuhacking.ca'
913

1014
try {
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`, {
15+
const res = await fetch(`${baseUrl}/api/users/me`, {
1216
headers: { Cookie: cookie || '' },
1317
})
1418

apps/portal/app/routes/logout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { redirect } from '@remix-run/node'
55
export const loader: LoaderFunction = async () => {
66
const adminURL
77
= process.env.NODE_ENV === 'development'
8-
? `${process.env.CUHACKING_2025_AXIOM_LOCAL_URL}/admin/logout`
9-
: `${process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}/admin/logout`
8+
? `http://localhost:8000/admin/logout`
9+
: `http://axiom.cuhacking.ca/admin/logout`
1010

1111
return redirect(adminURL)
1212
}

apps/portal/app/routes/profile.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { useLoaderData } from '@remix-run/react'
77

88
export const loader: LoaderFunction = async ({ request }) => {
99
const cookie = request.headers.get('Cookie')
10-
const API_URL = `${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}`
10+
11+
const baseUrl
12+
= process.env.NODE_ENV === 'development'
13+
? 'http://localhost:8000'
14+
: 'https://axiom.cuhacking.ca'
15+
16+
const API_URL = baseUrl
1117
try {
1218
const res = await fetch(`${API_URL}/api/users/me`, {
1319
headers: { Cookie: cookie || '' },

apps/portal/app/routes/registration.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { useLoaderData } from '@remix-run/react'
66

77
export const loader: LoaderFunction = async ({ request }) => {
88
const cookie = request.headers.get('Cookie')
9-
const API_URL = `${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}`
9+
const baseUrl
10+
= process.env.NODE_ENV === 'development'
11+
? 'http://localhost:8000'
12+
: 'https://axiom.cuhacking.ca'
13+
14+
const API_URL = baseUrl
1015
try {
1116
const me = await fetch(`${API_URL}/api/users/me`, {
1217
headers: { Cookie: cookie || '' },

apps/portal/app/routes/terms.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export const loader: LoaderFunction = async ({ request }) => {
1313
const cookie = request.headers.get('Cookie')
1414
const { legalData } = getLegalData()
1515

16-
const API_URL = `${process.env.NODE_ENV === 'development' ? process.env.CUHACKING_2025_AXIOM_LOCAL_URL : process.env.CUHACKING_2025_AXIOM_PUBLIC_URL}`
16+
const baseUrl
17+
= process.env.NODE_ENV === 'development'
18+
? 'http://localhost:8000'
19+
: 'https://axiom.cuhacking.ca'
20+
21+
const API_URL = baseUrl
1722
const user = await getCurrentUser({ cookie, API_URL })
1823

1924
if (!user) {

0 commit comments

Comments
 (0)