fix production prerender without auth config
This commit is contained in:
@@ -26,6 +26,12 @@ function required(name: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function hasAuthConfiguration(): boolean {
|
||||
return ["DATABASE_URL", "BETTER_AUTH_URL", "BETTER_AUTH_SECRET", "ADMIN_EMAIL"].every(
|
||||
(name) => Boolean(process.env[name]),
|
||||
);
|
||||
}
|
||||
|
||||
function createAuth() {
|
||||
const adminEmail = required("ADMIN_EMAIL");
|
||||
|
||||
@@ -109,6 +115,11 @@ export async function getAdminSession(): Promise<AdminSession | null> {
|
||||
};
|
||||
}
|
||||
|
||||
// Public pages can be prerendered without the runtime auth secret. In that
|
||||
// case the header simply omits the admin link; auth routes still fail loudly
|
||||
// through getAuth() when authentication is actually used.
|
||||
if (!hasAuthConfiguration()) return null;
|
||||
|
||||
const session = await getAuth().api.getSession({ headers: await headers() });
|
||||
if (
|
||||
!session?.session ||
|
||||
|
||||
Reference in New Issue
Block a user