Skip to content

Commit ade16c9

Browse files
committed
fix(portal): unable to authenticate users due to cross site cookies not enabled
1 parent ffa692f commit ade16c9

File tree

10 files changed

+38
-4
lines changed

10 files changed

+38
-4
lines changed

apps/portal/app/routes/_index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const loader: LoaderFunction = async ({ request }) => {
1313
try {
1414
const API_URL = baseUrl
1515
const res = await fetch(`${API_URL}/api/users/me`, {
16+
credentials: 'include',
1617
headers: { Cookie: cookie || '' },
1718
})
1819

apps/portal/app/routes/dashboard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const loader: LoaderFunction = async ({ request }) => {
1111
try {
1212
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
1313
const res = await fetch(`${API_URL}/api/users/me`, {
14+
credentials: 'include',
1415
headers: { Cookie: cookie || '' },
1516
})
1617

apps/portal/app/routes/login.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const loader: LoaderFunction = async ({ request }) => {
1313

1414
try {
1515
const res = await fetch(`${baseUrl}/api/users/me`, {
16+
credentials: 'include',
1617
headers: { Cookie: cookie || '' },
1718
})
1819

apps/portal/app/routes/profile.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const loader: LoaderFunction = async ({ request }) => {
1616
const API_URL = baseUrl
1717
try {
1818
const res = await fetch(`${API_URL}/api/users/me`, {
19+
credentials: 'include',
1920
headers: { Cookie: cookie || '' },
2021
})
2122

apps/portal/app/routes/registration.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const loader: LoaderFunction = async ({ request }) => {
1414
const API_URL = baseUrl
1515
try {
1616
const me = await fetch(`${API_URL}/api/users/me`, {
17+
credentials: 'include',
1718
headers: { Cookie: cookie || '' },
1819
})
1920

apps/portal/app/sessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const { getSession, commitSession, destroySession }
1919
{
2020
cookie: {
2121
name: '__session',
22-
secure: process.env.NODE_ENV === 'production',
22+
secure: true,
2323
secrets: [sessionSecret],
24-
sameSite: 'lax',
24+
sameSite: 'none',
2525
path: '/',
2626
httpOnly: true,
2727
},

libs/cms/auth/auth.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ import {
33
} from 'better-auth';
44

55
export const auth = betterAuth({
6+
advanced: {
7+
crossSubDomainCookies: {
8+
enabled: true,
9+
domain: ".cuhacking.ca",
10+
},
11+
defaultCookieAttributes: {
12+
secure: true,
13+
httpOnly: true,
14+
sameSite: "none",
15+
partitioned: true,
16+
},
17+
},
618
socialProviders: {
719
linkedin: {
8-
clientId: process.env.LINKEDIN_CLIENT_ID,
9-
clientSecret: process.env.LINKEDIN_CLIENT_SECRET
20+
clientId: process.env.LINKEDIN_CLIENT_ID || '',
21+
clientSecret: process.env.LINKEDIN_CLIENT_SECRET || ''
1022
}
1123
},
1224

libs/cms/configs/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ import { s3Storage } from '@payloadcms/storage-s3'
2727
import sharp from "sharp";
2828

2929
export const baseConfig = {
30+
auth: {
31+
cookies: {
32+
payloadToken: {
33+
domain: ".cuhacking.ca",
34+
path: "/",
35+
secure: true,
36+
httpOnly: true,
37+
sameSite: "None",
38+
},
39+
},
40+
},
3041
globals: [
3142
Hackathon2025,
3243
],

libs/db/collections/models/Users.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ export const Users: CollectionConfig = {
259259
slug: "users",
260260
// auth: true,
261261
auth: {
262+
cookies: {
263+
domain: process.env.NODE_ENV === 'development' ? 'localhost' : '.cuhacking.ca',
264+
sameSite: 'None',
265+
secure: true
266+
},
262267
disableLocalStrategy: {
263268
enableFields: true,
264269
optionalPassword: true,

libs/portal/features/profile/api/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { UserDetails } from '@cuhacking/portal/types/user'
33
export async function getCurrentUser({ cookie, API_URL }: { cookie: string | null, API_URL: string }): Promise<UserDetails | null> {
44
try {
55
const response = await fetch(`${API_URL}/api/users/me`, {
6+
credentials: 'include',
67
headers: { Cookie: cookie || '' },
78
})
89

0 commit comments

Comments
 (0)