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 {