Skip to content

Commit a0b6359

Browse files
Copilotlstein
andauthored
Fix: Clear auth state when switching from multiuser to single-user mode (#86)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
1 parent a36e110 commit a0b6359

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

invokeai/frontend/web/src/features/auth/components/ProtectedRoute.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit
2222
const { data: setupStatus } = useGetSetupStatusQuery();
2323
const multiuserEnabled = setupStatus?.multiuser_enabled ?? true; // Default to true for safety
2424

25-
// Only fetch user if we have a token but no user data
26-
const shouldFetchUser = isAuthenticated && token && !user;
25+
// Only fetch user if we have a token but no user data, and multiuser mode is enabled
26+
const shouldFetchUser = multiuserEnabled && isAuthenticated && token && !user;
2727
const {
2828
data: currentUser,
2929
isLoading: isLoadingUser,
@@ -57,6 +57,10 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit
5757
useEffect(() => {
5858
// If multiuser is disabled, allow access without authentication
5959
if (!multiuserEnabled) {
60+
// Clear any persisted auth state when switching to single-user mode
61+
if (isAuthenticated) {
62+
dispatch(logout());
63+
}
6064
return;
6165
}
6266

@@ -66,7 +70,7 @@ export const ProtectedRoute = memo(({ children, requireAdmin = false }: PropsWit
6670
} else if (!isLoadingUser && isAuthenticated && user && requireAdmin && !user.is_admin) {
6771
navigate('/', { replace: true });
6872
}
69-
}, [isAuthenticated, isLoadingUser, requireAdmin, user, navigate, multiuserEnabled]);
73+
}, [isAuthenticated, isLoadingUser, requireAdmin, user, navigate, multiuserEnabled, dispatch]);
7074

7175
// In single-user mode, always allow access
7276
if (!multiuserEnabled) {

0 commit comments

Comments
 (0)