From f26e9742ddf0243b973544d60c9569998ebf11ca Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj <31964049+isekovanic@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:18:47 +0100 Subject: [PATCH] fix: add safeguard for querying app settings (#2765) * fix: add safeguard for querying app settings * fix: test --- .../src/components/Chat/hooks/__tests__/useAppSettings.test.tsx | 1 + package/src/components/Chat/hooks/useAppSettings.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx b/package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx index c83111b9f0..3f96bdab75 100644 --- a/package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx +++ b/package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx @@ -18,6 +18,7 @@ describe('useAppSettings', () => { auto_translation_enabled: true, }), ), + userID: 'some-user-id', } as unknown as StreamChat, isOnline, false, diff --git a/package/src/components/Chat/hooks/useAppSettings.ts b/package/src/components/Chat/hooks/useAppSettings.ts index b3e77552db..f424f8d18e 100644 --- a/package/src/components/Chat/hooks/useAppSettings.ts +++ b/package/src/components/Chat/hooks/useAppSettings.ts @@ -22,6 +22,8 @@ export const useAppSettings = < * Fetches app settings from the backend when offline support is disabled. */ const enforceAppSettingsWithoutOfflineSupport = async () => { + if (!client.userID) return; + try { const appSettings = await client.getAppSettings(); if (isMounted.current) {