fix production prerender without auth config
CI / Verify (push) Successful in 55s
CI / Build immutable images and deploy (push) Successful in 1m42s

This commit is contained in:
2026-08-31 00:59:20 +07:00 Unverified
parent e3692fe75b
commit 4bf9d9098f
3 changed files with 43 additions and 10 deletions
+11
View File
@@ -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 ||