@@ -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