fix: update authentication to support http://dhg.lol:51193

This commit is contained in:
2026-03-31 09:16:58 -07:00
parent f58698398e
commit 103c62497c
2 changed files with 15 additions and 6 deletions
+14 -6
View File
@@ -3,31 +3,39 @@
* This provides getSession() for use in server components * This provides getSession() for use in server components
*/ */
import { cookies } from "next/headers"; import { cookies, headers } from "next/headers";
export async function getSession() { export async function getSession() {
try { try {
const cookieStore = await cookies(); const cookieStore = await cookies();
const headerStore = await headers();
// Get the session token from cookies // 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) { if (!sessionToken) {
return null; 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 // Make a request to the Better Auth API to get the session
// This is the standard way Better Auth handles session verification const response = await fetch(`${baseUrl}/api/auth/get-session?disableCookieCache=true`, {
// 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`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Cookie': `${sessionToken.name}=${sessionToken.value}` 'Cookie': `${sessionToken.name}=${sessionToken.value}`,
}, },
cache: 'no-store', cache: 'no-store',
}); });
if (!response.ok) { if (!response.ok) {
console.log('Session API response not OK:', response.status);
return null; return null;
} }
+1
View File
@@ -40,6 +40,7 @@ export const auth = betterAuth({
origins.push( origins.push(
"https://euchre.notsosm.art", "https://euchre.notsosm.art",
"http://euchre.notsosm.art", "http://euchre.notsosm.art",
"http://dhg.lol:51193",
"http://localhost:3000", "http://localhost:3000",
"http://127.0.0.1:3000", "http://127.0.0.1:3000",
"http://0.0.0.0:3000" "http://0.0.0.0:3000"