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;