Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

studio/frontend: reconcile stale must_change_password localStorage flag (#5576)

Daniel Hane4edd34e3c02
diff --git a/studio/frontend/src/app/auth-guards.ts b/studio/frontend/src/app/auth-guards.ts
index 52230f0b6f1..6849f380b80 100644
--- a/studio/frontend/src/app/auth-guards.ts
+++ b/studio/frontend/src/app/auth-guards.ts
@@ -9,6 +9,7 @@ import {
hasRefreshToken,
mustChangePassword,
refreshSession,
+ setMustChangePassword,
} from "@/features/auth";
async function hasActiveSession(): Promise<boolean> {
@@ -26,7 +27,12 @@ async function fetchAuthStatus(): Promise<AuthStatus> {
try {
const res = await fetch(apiUrl("/api/auth/status"));
if (!res.ok) return { initialized: true, requires_password_change: mustChangePassword() };
- return (await res.json()) as AuthStatus;
+ const status = (await res.json()) as AuthStatus;
+ // Server truth wins; keep localStorage in sync both ways.
+ if (status.requires_password_change !== mustChangePassword()) {
+ setMustChangePassword(status.requires_password_change);
+ }
+ return status;
} catch {
return { initialized: true, requires_password_change: mustChangePassword() };
}
@@ -61,6 +67,8 @@ export async function requireGuest(): Promise<void> {
throw redirect({ to: "/chat" });
}
if (!(await hasActiveSession())) return;
+ // Reconcile localStorage before routing.
+ await fetchAuthStatus();
throw redirect({ to: getPostAuthRoute() });
}
diff --git a/studio/frontend/src/features/auth/api.ts b/studio/frontend/src/features/auth/api.ts
index 98c5757d2ac..cc5749a9233 100644
--- a/studio/frontend/src/features/auth/api.ts
+++ b/studio/frontend/src/features/auth/api.ts
@@ -65,7 +65,11 @@ async function redirectToAuth(): Promise<void> {
const res = await fetch(apiUrl("/api/auth/status"));
if (res.ok) {
const data = (await res.json()) as { requires_password_change: boolean };
- if (data.requires_password_change || mustChangePassword()) target = "/change-password";
+ // Server truth wins; keep localStorage in sync both ways.
+ if (data.requires_password_change !== mustChangePassword()) {
+ setMustChangePassword(data.requires_password_change);
+ }
+ if (data.requires_password_change) target = "/change-password";
}
} catch {
// Fall through to /login on error
diff --git a/studio/frontend/src/features/auth/components/auth-form.tsx b/studio/frontend/src/features/auth/components/auth-form.tsx
index a10c77e9faa..3ac97929d8f 100644
--- a/studio/frontend/src/features/auth/components/auth-form.tsx
+++ b/studio/frontend/src/features/auth/components/auth-form.tsx
@@ -105,12 +105,17 @@ export function AuthForm({ mode }: AuthFormProps): ReactElement | null {
setInitialized(result.initialized);
setRequiresPasswordChange(result.requires_password_change);
+ // Server truth wins; keep localStorage in sync both ways.
+ if (result.requires_password_change !== mustChangePassword()) {
+ setMustChangePassword(result.requires_password_change);
+ }
+
// Redirect between login ↔ change-password based on server state
if (mode === "login" && result.requires_password_change) {
navigate({ to: "/change-password" });
return;
}
- if (mode === "change-password" && !result.requires_password_change && !mustChangePassword()) {
+ if (mode === "change-password" && !result.requires_password_change) {
navigate({ to: "/login" });
return;
}
@@ -163,14 +168,14 @@ export function AuthForm({ mode }: AuthFormProps): ReactElement | null {
const blockedByState =
initialized === false ||
(mode === "login" && requiresPasswordChange) ||
- (mode === "change-password" && !requiresPasswordChange && !mustChangePassword());
+ (mode === "change-password" && !requiresPasswordChange);
let helperText: string | null = null;
if (initialized === false) {
helperText = "Auth is still bootstrapping the default admin account.";
} else if (isLoginMode && requiresPasswordChange) {
helperText = "Sign in once with the seeded credentials to change the password.";
- } else if (!isLoginMode && !requiresPasswordChange && !mustChangePassword()) {
+ } else if (!isLoginMode && !requiresPasswordChange) {
helperText = "Password already updated. Use the login screen.";
}
const title = isLoginMode ? "Welcome back" : "Setup your account";