From 69d6956d2362e4ff6d9da3f48dfdf73adcc4f2a0 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 5 Sep 2026 10:39:06 +0200 Subject: [PATCH] feat(login): Verantwortliche landen nach Login auf /dashboard Materialverantwortlicher/Leitungsverantwortlicher/Administration werden nach Login direkt zum neuen Leitungs-Dashboard geleitet statt zur Objektliste. rollen im AuthContext laden asynchron nach - daher hier direkt /auth/me abfragen statt auf den Context zu warten. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01KC8HYvv6UkCVYheYiTw9DD --- frontend/src/pages/LoginPage.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/LoginPage.tsx b/frontend/src/pages/LoginPage.tsx index fe1f42e..8f1931b 100644 --- a/frontend/src/pages/LoginPage.tsx +++ b/frontend/src/pages/LoginPage.tsx @@ -1,7 +1,11 @@ import { useState, type FormEvent } from "react"; import { useNavigate } from "react-router-dom"; +import { apiRequest } from "../api/client"; import { useAuth } from "../auth/AuthContext"; +import type { Me } from "../api/types"; + +const VERANTWORTLICH_ROLLEN = ["administration", "materialverantwortlicher", "leitungsverantwortlicher"]; export function LoginPage() { const { login } = useAuth(); @@ -17,7 +21,12 @@ export function LoginPage() { setWirdGeladen(true); try { await login(username, password); - navigate("/objekte"); + // rollen im AuthContext werden erst asynchron nachgeladen (eigener + // useEffect) - für die Landingpage-Entscheidung direkt nach Login + // selbst /auth/me abfragen statt auf den Context zu warten. + const me = await apiRequest("/auth/me"); + const istVerantwortlich = me.rollen.some((r) => VERANTWORTLICH_ROLLEN.includes(r)); + navigate(istVerantwortlich ? "/dashboard" : "/objekte"); } catch { setFehler("Login oder Passwort falsch"); } finally {