From 4e569d6113bccf0ef7eee236225f311d3d9d2259 Mon Sep 17 00:00:00 2001 From: Zewed Date: Wed, 31 Jan 2024 12:01:41 -0800 Subject: [PATCH] fix --- .../app/chat/[chatId]/hooks/useChatsList.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/app/chat/[chatId]/hooks/useChatsList.ts b/frontend/app/chat/[chatId]/hooks/useChatsList.ts index 4a38fb71decf..0e9822780fbe 100644 --- a/frontend/app/chat/[chatId]/hooks/useChatsList.ts +++ b/frontend/app/chat/[chatId]/hooks/useChatsList.ts @@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next"; import { CHATS_DATA_KEY } from "@/lib/api/chat/config"; import { useChatApi } from "@/lib/api/chat/useChatApi"; import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext"; +import { useSupabase } from "@/lib/context/SupabaseProvider"; import { useToast } from "@/lib/hooks"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types @@ -14,18 +15,21 @@ export const useChatsList = () => { const { setAllChats, setIsLoading } = useChatsContext(); const { publish } = useToast(); const { getChats } = useChatApi(); + const { session } = useSupabase(); const fetchAllChats = async () => { - try { - const response = await getChats(); - - return response.reverse(); - } catch (error) { - console.error(error); - publish({ - variant: "danger", - text: t("errorFetching", { ns: "chat" }), - }); + if (session) { + try { + const response = await getChats(); + + return response.reverse(); + } catch (error) { + console.error(error); + publish({ + variant: "danger", + text: t("errorFetching", { ns: "chat" }), + }); + } } };