first commit
Docker-Images bauen und veroeffentlichen / build-and-push (push) Failing after 1m32s

This commit is contained in:
Nick Szaunig committed 2026-09-27 06:06:56 +02:00
commit 59bb5a38a3
132 files changed
+19435

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
/**
* Serverseitige Zugriffskontrolle fuer den Adminbereich. Wird von JEDER
* Admin-Seite, Server-Action und jedem Admin-Endpunkt aufgerufen — der
* Proxy (src/proxy.ts) leitet nur vorab um und ist keine Sicherheitsgrenze.
*/
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import type { Actor } from "./audit";
import { getAuth } from "./auth";
export type AdminUser = { id: string; email: string; name: string; twoFactorEnabled: boolean };
async function currentAdmin(): Promise<AdminUser | null> {
const session = await getAuth().api.getSession({ headers: await headers() });
if (!session) return 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) };
}
/** Fuer Seiten: leitet zur Anmeldung bzw. zur 2FA-Einrichtung um. */
export async function requireAdminPage(options: { allowWithout2fa?: boolean } = {}): Promise<AdminUser> {
const admin = await currentAdmin();
if (!admin) redirect("/admin/anmelden");
if (!admin.twoFactorEnabled && !options.allowWithout2fa) redirect("/admin/sicherheit");
return admin;
}
/** Fuer Server-Actions und Endpunkte: wirft statt umzuleiten. */
export async function requireAdminAction(): Promise<AdminUser> {
const admin = await currentAdmin();
if (!admin || !admin.twoFactorEnabled) throw new Error("Nicht berechtigt.");
return admin;
}
/** Fuer Route-Handler: null statt Ausnahme. */
export async function adminOrNull(): Promise<AdminUser | null> {
const admin = await currentAdmin();
return admin?.twoFactorEnabled ? admin : null;
}
export function adminActor(admin: AdminUser): Actor {
return { type: "ADMIN", id: admin.id };
}