From 3c26d5b4765048aca09511d6592c5e1e3d00f7d9 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Tue, 11 Mar 2025 22:19:09 -0700 Subject: [PATCH] Added cookie name for app seperation --- apps/dispatch/.env.example | 5 +++-- .../app/api/auth/[...nextauth]/auth.ts | 11 +++++++++-- apps/hub/.env.example | 4 ++-- apps/hub/app/api/auth/[...nextauth]/auth.ts | 19 ++++++++++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/apps/dispatch/.env.example b/apps/dispatch/.env.example index aa0fb996..88aa9476 100644 --- a/apps/dispatch/.env.example +++ b/apps/dispatch/.env.example @@ -1,5 +1,6 @@ NEXTAUTH_SECRET= +NEXTAUTH_COOKIE_PREFIX= +NEXTAUTH_SECRET= NEXT_PUBLIC_PUBLIC_URL= NEXT_PUBLIC_HUB_URL= -NEXT_PUBLIC_SERVICE_ID= -NEXTAUTH_SECRET= +NEXT_PUBLIC_SERVICE_ID= \ No newline at end of file diff --git a/apps/dispatch/app/api/auth/[...nextauth]/auth.ts b/apps/dispatch/app/api/auth/[...nextauth]/auth.ts index 79259789..c3b66546 100644 --- a/apps/dispatch/app/api/auth/[...nextauth]/auth.ts +++ b/apps/dispatch/app/api/auth/[...nextauth]/auth.ts @@ -39,11 +39,18 @@ export const options: AuthOptions = { secret: process.env.NEXTAUTH_SECRET, cookies: { sessionToken: { - name: `next-auth.session-token-${process.env.NEXTAUTH_URL}`, + name: `${process.env.NEXTAUTH_COOKIE_PREFIX}-next-auth.session-token`, // Ändere den Namen für App 1 + options: { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + path: "/", + }, + }, + csrfToken: { + name: `${process.env.NEXTAUTH_COOKIE_PREFIX}-next-auth.csrf-token`, options: { httpOnly: true, secure: process.env.NODE_ENV === "production", - sameSite: "lax", path: "/", }, }, diff --git a/apps/hub/.env.example b/apps/hub/.env.example index c66c3a3d..fa7e22ba 100644 --- a/apps/hub/.env.example +++ b/apps/hub/.env.example @@ -1,10 +1,10 @@ NEXTAUTH_URL= NEXTAUTH_SECRET= +NEXT_PUBLIC_MOODLE_URL= DATABASE_URL= DISCORD_OAUTH_CLIENT_ID= DISCORD_OAUTH_SECRET= DISCORD_BOT_TOKEN= NEXT_PUBLIC_DISCORD_URL= DISCORD_REDIRECT= -MOODLE_TOKEN= -NEXT_PUBLIC_MOODLE_URL= \ No newline at end of file +MOODLE_TOKEN= \ No newline at end of file diff --git a/apps/hub/app/api/auth/[...nextauth]/auth.ts b/apps/hub/app/api/auth/[...nextauth]/auth.ts index 1558d356..8a828d8d 100644 --- a/apps/hub/app/api/auth/[...nextauth]/auth.ts +++ b/apps/hub/app/api/auth/[...nextauth]/auth.ts @@ -36,7 +36,24 @@ export const options: AuthOptions = { strategy: "jwt", maxAge: 30 * 24 * 60 * 60, }, - + cookies: { + sessionToken: { + name: `${process.env.NEXTAUTH_COOKIE_PREFIX}-next-auth.session-token`, // Ändere den Namen für App 1 + options: { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + path: "/", + }, + }, + csrfToken: { + name: `${process.env.NEXTAUTH_COOKIE_PREFIX}-next-auth.csrf-token`, + options: { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + path: "/", + }, + }, + }, adapter: PrismaAdapter(prisma as any), callbacks: { jwt: async ({ token, user }) => {