From 78b5783bb0adbbcc8721e362fb5ddc8321dabada Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 03:19:51 +0000 Subject: [PATCH] Fix: Clear auth state when switching from multiuser to single-user mode Co-authored-by: lstein <111189+lstein@users.noreply.github.com> --- .../src/features/auth/components/ProtectedRoute.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/features/auth/components/ProtectedRoute.tsx b/invokeai/frontend/web/src/features/auth/components/ProtectedRoute.tsx index c5e85ccf7c8..a53692b1500 100644 --- a/invokeai/frontend/web/src/features/auth/components/ProtectedRoute.tsx +++ b/invokeai/frontend/web/src/features/auth/components/ProtectedRoute.tsx @@ -22,8 +22,8 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit const { data: setupStatus } = useGetSetupStatusQuery(); const multiuserEnabled = setupStatus?.multiuser_enabled ?? true; // Default to true for safety - // Only fetch user if we have a token but no user data - const shouldFetchUser = isAuthenticated && token && !user; + // Only fetch user if we have a token but no user data, and multiuser mode is enabled + const shouldFetchUser = multiuserEnabled && isAuthenticated && token && !user; const { data: currentUser, isLoading: isLoadingUser, @@ -57,6 +57,10 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit useEffect(() => { // If multiuser is disabled, allow access without authentication if (!multiuserEnabled) { + // Clear any persisted auth state when switching to single-user mode + if (isAuthenticated) { + dispatch(logout()); + } return; } @@ -66,7 +70,7 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit } else if (!isLoadingUser && isAuthenticated && user && requireAdmin && !user.is_admin) { navigate('/', { replace: true }); } - }, [isAuthenticated, isLoadingUser, requireAdmin, user, navigate, multiuserEnabled]); + }, [isAuthenticated, isLoadingUser, requireAdmin, user, navigate, multiuserEnabled, dispatch]); // In single-user mode, always allow access if (!multiuserEnabled) {