fix(auth): refresh cached user after self-role edit so RoleSwitcher shows up
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

extra_roles changes made to the currently-logged-in admin's own account
weren't reflected until logout/login, since AuthContext only fetches
/users/me once at mount. Now refetches it when the edited user is the
caller themselves.
This commit is contained in:
kitos
2026-07-22 09:41:52 +02:00
parent 06c913955c
commit 66951086fb
2 changed files with 12 additions and 1 deletions
+5
View File
@@ -28,6 +28,10 @@ interface AuthState {
* Reloads the page afterward so every role-gated component (nav, route
* guards, etc.) re-evaluates cleanly against the new role. */
switchRole: (role: string) => Promise<void>;
/** Re-fetch the current user from /users/me — call after an admin edits
* the logged-in user's own role/extra_roles so gated UI (e.g. the role
* switcher) picks it up without requiring a logout/login. */
refreshUser: () => Promise<void>;
}
const AuthContext = createContext<AuthState | undefined>(undefined);
@@ -93,6 +97,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
login,
logout,
switchRole,
refreshUser,
}}
>
{children}