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
*/
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;
}