fix: update authentication to support http://dhg.lol:51193
This commit is contained in:
+14
-6
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user