Fix localhost hardcoding in auth - use Vercel env vars
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { headers as nextHeaders } from 'next/headers'
|
import { headers as nextHeaders } from 'next/headers'
|
||||||
|
import { BASE_URL } from '@/lib/utils'
|
||||||
const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current session from Better Auth backend (server-side)
|
* Get the current session from Better Auth backend (server-side)
|
||||||
@@ -10,7 +9,7 @@ export async function getSession() {
|
|||||||
const headersList = await nextHeaders()
|
const headersList = await nextHeaders()
|
||||||
|
|
||||||
// Make authenticated request to the auth backend to get session
|
// Make authenticated request to the auth backend to get session
|
||||||
const response = await fetch(`${API_URL}/api/auth/get-session`, {
|
const response = await fetch(`${BASE_URL}/api/auth/get-session`, {
|
||||||
headers: {
|
headers: {
|
||||||
cookie: headersList.get('cookie') || '',
|
cookie: headersList.get('cookie') || '',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,8 +11,32 @@ function getAuthURL(): string {
|
|||||||
return window.location.origin
|
return window.location.origin
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSR fallback
|
// SSR fallback - detect environment from Vercel variables
|
||||||
return process.env.BETTER_AUTH_URL || 'http://localhost:3000'
|
const isDevelopment =
|
||||||
|
process.env.NODE_ENV === 'development' ||
|
||||||
|
process.env.NEXT_PUBLIC_VERCEL_ENV === 'development'
|
||||||
|
const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'
|
||||||
|
const isProduction =
|
||||||
|
process.env.NODE_ENV === 'production' || process.env.NEXT_PUBLIC_VERCEL_ENV === 'production'
|
||||||
|
|
||||||
|
if (isDevelopment) {
|
||||||
|
return process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3000}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPreview && process.env.NEXT_PUBLIC_VERCEL_URL) {
|
||||||
|
return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isProduction) {
|
||||||
|
return (
|
||||||
|
process.env.NEXT_PUBLIC_APP_URL ||
|
||||||
|
(process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL
|
||||||
|
? `https://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`
|
||||||
|
: 'https://editor.pascal.app')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'http://localhost:3000'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user