From fb4747cfeb4000f45e7bf9c98b8950dd70afa145 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 10 Jun 2026 13:47:09 +0200 Subject: [PATCH] auth: Diagnose-Log bei abgelehntem Authentik-Login Loggt bei AccessDenied die empfangenen Gruppen + erwartete Admin-Gruppe; bei leerer Gruppenliste Hinweis auf fehlendes 'groups'-Scope-Mapping. Erleichtert die Diagnose der Authentik-Gruppensteuerung im Betrieb. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/auth.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index 3e01138..1be0661 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -91,9 +91,22 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ async signIn({ user, account, profile }) { if (account?.provider === "authentik") { const email = user.email; - if (!email) return false; + if (!email) { + console.warn("[auth] Authentik-Login ohne E-Mail abgelehnt."); + return false; + } const groups = extractGroups(profile); - if (!isAdminGroupMember(groups, env.AUTHENTIK_ADMIN_GROUP)) return false; + if (!isAdminGroupMember(groups, env.AUTHENTIK_ADMIN_GROUP)) { + console.warn( + `[auth] Authentik-Login abgelehnt: "${email}" ist nicht in Gruppe ` + + `"${env.AUTHENTIK_ADMIN_GROUP}". Erhaltene Gruppen: ${JSON.stringify(groups)}` + + (groups.length + ? "" + : " — leer: vermutlich fehlt das 'groups'-Scope-Mapping im " + + "Authentik-Provider (oder der 'groups'-Scope wird nicht angefragt)."), + ); + return false; + } const u = await upsertAuthentikAdmin(email, user.name ?? null); user.id = u.id; user.role = u.rolle;