Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(device): gate listDevices request behind login state (#15876)

Arvin Xue444a886ffea
diff --git a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
index 003a27bcbd9..139fb2e0c62 100644
--- a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
+++ b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
@@ -26,6 +26,8 @@ import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
import { deviceSelectors, useDeviceStore } from '@/store/device';
import { useElectronStore } from '@/store/electron';
+import { useUserStore } from '@/store/user';
+import { authSelectors } from '@/store/user/selectors';
import { openAddWorkingDirModal } from './AddWorkingDirModal';
import DirIcon from './DirIcon';
@@ -246,8 +248,10 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
const { t } = useTranslation('device');
const [open, setOpen] = useState(false);
- // Populate the device store (SWR dedupes across callers).
- useDeviceStore((s) => s.useFetchDevices)();
+ // Populate the device store (SWR dedupes across callers). Devices sit behind an
+ // authed lambda procedure, so only fetch once signed in (desktop always fetches).
+ const isLogin = useUserStore(authSelectors.isLogin);
+ useDeviceStore((s) => s.useFetchDevices)(isLogin || isDesktop);
// One-time fold of legacy localStorage recents into device.workingDirs.
useMigrateDeviceRecents();
diff --git a/src/hooks/useEffectiveWorkingDirectory.ts b/src/hooks/useEffectiveWorkingDirectory.ts
index 74d80f6b8b9..822df74b605 100644
--- a/src/hooks/useEffectiveWorkingDirectory.ts
+++ b/src/hooks/useEffectiveWorkingDirectory.ts
@@ -11,6 +11,8 @@ import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
import { deviceSelectors, useDeviceStore } from '@/store/device';
import { useElectronStore } from '@/store/electron';
+import { useUserStore } from '@/store/user';
+import { authSelectors } from '@/store/user/selectors';
/**
* The agent's effective working directory under the unified precedence:
@@ -25,7 +27,10 @@ import { useElectronStore } from '@/store/electron';
*/
export const useEffectiveWorkingDirectory = (agentId?: string): string | undefined => {
// Self-populate the device store (SWR dedupes by key across all callers).
- useDeviceStore((s) => s.useFetchDevices)();
+ // Devices live behind an authed lambda procedure, so only fetch once signed in
+ // (desktop always fetches β€” it relies on the local device's saved cwd).
+ const isLogin = useUserStore(authSelectors.isLogin);
+ useDeviceStore((s) => s.useFetchDevices)(isLogin || isDesktop);
const agencyConfig = useAgentStore((s) =>
agentId ? agentByIdSelectors.getAgencyConfigById(agentId)(s) : undefined,
diff --git a/src/routes/(main)/settings/devices/features/DeviceList.tsx b/src/routes/(main)/settings/devices/features/DeviceList.tsx
index 56c9b2d7b3a..577c8eeb191 100644
--- a/src/routes/(main)/settings/devices/features/DeviceList.tsx
+++ b/src/routes/(main)/settings/devices/features/DeviceList.tsx
@@ -17,6 +17,8 @@ import { useTranslation } from 'react-i18next';
import { lambdaQuery } from '@/libs/trpc/client';
import { useElectronStore } from '@/store/electron';
+import { useUserStore } from '@/store/user';
+import { authSelectors } from '@/store/user/selectors';
import ConnectDeviceModal from './ConnectDeviceModal';
import DeviceDetailPanel from './DeviceDetailPanel';
@@ -163,7 +165,11 @@ const ConnectOption = memo<ConnectOptionProps>(({ icon, title, desc, badge, onCl
const DeviceList = memo(() => {
const { t } = useTranslation('setting');
+ // Devices come from an authed lambda procedure, so only query once signed in
+ // (desktop always queries β€” it lists the local device's registered cwd).
+ const isLogin = useUserStore(authSelectors.isLogin);
const { data: devices, isLoading } = lambdaQuery.device.listDevices.useQuery(undefined, {
+ enabled: isLogin || isDesktop,
staleTime: 30_000,
});
diff --git a/src/store/device/action.ts b/src/store/device/action.ts
index b64c0edee8c..dd02ae348be 100644
--- a/src/store/device/action.ts
+++ b/src/store/device/action.ts
@@ -128,7 +128,7 @@ export class DeviceActionImpl {
}
};
- useFetchDevices = (enabled = true): SWRResponse<DeviceListItem[]> =>
+ useFetchDevices = (enabled = false): SWRResponse<DeviceListItem[]> =>
useClientDataSWR<DeviceListItem[]>(
enabled ? deviceKeys.listDevices() : null,
() => deviceService.listDevices(),