diff --git a/src/lib/auth-simple.ts b/src/lib/auth-simple.ts index 8a29a6a..26c1c41 100644 --- a/src/lib/auth-simple.ts +++ b/src/lib/auth-simple.ts @@ -3,31 +3,39 @@ * This provides getSession() for use in server components */ -import { cookies } from "next/headers"; +import { cookies, headers } from "next/headers"; export async function getSession() { try { const cookieStore = await cookies(); + const headerStore = await headers(); // Get the session token from cookies - const sessionToken = cookieStore.get('better-auth.session_token'); + // Try both with and without __Secure prefix + let sessionToken = cookieStore.get('better-auth.session_token'); + if (!sessionToken) { + sessionToken = cookieStore.get('__Secure-better-auth.session_token'); + } if (!sessionToken) { return null; } + // Use BETTER_AUTH_URL from environment for internal fetch + // This ensures consistent origin for server-side requests + const baseUrl = process.env.BETTER_AUTH_URL || 'http://localhost:3000'; + // Make a request to the Better Auth API to get the session - // This is the standard way Better Auth handles session verification - // Use disableCookieCache to bypass the cookie cache and get fresh data from the database - const response = await fetch(`${process.env.BETTER_AUTH_URL || 'http://localhost:3000'}/api/auth/get-session?disableCookieCache=true`, { + const response = await fetch(`${baseUrl}/api/auth/get-session?disableCookieCache=true`, { method: 'GET', headers: { - 'Cookie': `${sessionToken.name}=${sessionToken.value}` + 'Cookie': `${sessionToken.name}=${sessionToken.value}`, }, cache: 'no-store', }); if (!response.ok) { + console.log('Session API response not OK:', response.status); return null; } diff --git a/src/lib/auth.ts b/src/lib/auth.ts index f49f611..275016b 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -40,6 +40,7 @@ export const auth = betterAuth({ origins.push( "https://euchre.notsosm.art", "http://euchre.notsosm.art", + "http://dhg.lol:51193", "http://localhost:3000", "http://127.0.0.1:3000", "http://0.0.0.0:3000"