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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KC8HYvv6UkCVYheYiTw9DD
This commit is contained in:
@@ -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<Me>("/auth/me");
|
||||
const istVerantwortlich = me.rollen.some((r) => VERANTWORTLICH_ROLLEN.includes(r));
|
||||
navigate(istVerantwortlich ? "/dashboard" : "/objekte");
|
||||
} catch {
|
||||
setFehler("Login oder Passwort falsch");
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user