From 356ab18ec02db220faa0a9b236128dc9460a285e Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 22 Apr 2026 15:46:40 +0200 Subject: [PATCH] fix: Add /profiles/me endpoint for session persistence - AuthContext checks /profiles/me on mount to restore session - Without this endpoint, users had to re-login on every refresh - Returns current user's profile based on auth token Issue: Session persistence broken --- backend/routers/profiles.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/routers/profiles.py b/backend/routers/profiles.py index b9937ea..6bff787 100644 --- a/backend/routers/profiles.py +++ b/backend/routers/profiles.py @@ -29,6 +29,20 @@ def get_pid(x_profile_id: Optional[str] = Header(default=None)) -> str: raise HTTPException(400, "Kein Profil gefunden") +# ── Current User Profile ────────────────────────────────────────────────────── +@router.get("/profiles/me") +def get_current_profile(session=Depends(require_auth)): + """Get current user's profile (for auth check on refresh).""" + profile_id = session['profile_id'] + with get_db() as conn: + cur = get_cursor(conn) + cur.execute("SELECT * FROM profiles WHERE id=%s", (profile_id,)) + row = cur.fetchone() + if not row: + raise HTTPException(404, "Profil nicht gefunden") + return r2d(row) + + # ── Admin Profile Management ────────────────────────────────────────────────── @router.get("/profiles") def list_profiles(session=Depends(require_auth)):