From 8c77af42ffe35506c2269791c0c147dc99dc4358 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Tue, 16 Jun 2026 02:12:59 +0200 Subject: [PATCH] fix(auth): always seed the active account into the switch list Sessions created before multi-session existed had no account_ids, so adding a second account left the first one (e.g. the long-lived session) absent from the switcher. current_user now ensures the active user_id is always present in account_ids, so the switch list is never missing the account you're using. --- backend/app/auth.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/app/auth.py b/backend/app/auth.py index ac00fca..685a211 100644 --- a/backend/app/auth.py +++ b/backend/app/auth.py @@ -232,6 +232,12 @@ def current_user(request: Request, db: Session = Depends(get_db)) -> User: if user is None: request.session.clear() raise HTTPException(status_code=401, detail="Not authenticated") + # Always keep the active account in the switchable list — covers sessions created before + # multi-session existed (their account_ids was never seeded), so the switcher isn't empty. + accounts = request.session.get("account_ids") or [] + if user_id not in accounts: + accounts.append(user_id) + request.session["account_ids"] = accounts[-MAX_SESSION_ACCOUNTS:] return user