fix: Admin-Routen nicht vorab rendern (Docker-Build ohne Secrets)
Docker-Images bauen und veroeffentlichen / build-and-push (push) Successful in 4m25s

next build versuchte /admin statisch zu rendern. currentAdmin() rief dabei
getAuth() vor headers() auf und scheiterte ohne BETTER_AUTH_SECRET im
Build-Container. Jetzt werden zuerst die Request-Header gelesen, wodurch
alle Admin-Routen dynamisch sind und Auth erst zur Laufzeit geladen wird.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-09-27 12:42:25 +02:00
1 parent 59bb5a38a3
commit 771eeee887
1 file changed
+5 -1
+5 -1
View File
@@ -11,7 +11,11 @@ import { getAuth } from "./auth";
export type AdminUser = { id: string; email: string; name: string; twoFactorEnabled: boolean }; export type AdminUser = { id: string; email: string; name: string; twoFactorEnabled: boolean };
async function currentAdmin(): Promise<AdminUser | null> { async function currentAdmin(): Promise<AdminUser | null> {
const session = await getAuth().api.getSession({ headers: await headers() }); // Zuerst die Request-Header lesen: das macht jede Admin-Route dynamisch.
// Sonst versucht "next build" sie vorab zu rendern und scheitert ohne
// Secrets im Container (getAuth() braucht BETTER_AUTH_SECRET).
const requestHeaders = await headers();
const session = await getAuth().api.getSession({ headers: requestHeaders });
if (!session) return null; if (!session) return null;
const user = session.user as typeof session.user & { twoFactorEnabled?: boolean | null }; const user = session.user as typeof session.user & { twoFactorEnabled?: boolean | null };
return { id: user.id, email: user.email, name: user.name, twoFactorEnabled: Boolean(user.twoFactorEnabled) }; return { id: user.id, email: user.email, name: user.name, twoFactorEnabled: Boolean(user.twoFactorEnabled) };