fix(frontend): fetch chat only if session exist (#2130)

This commit is contained in:
Antoine Dewez 2024-01-31 12:48:37 -08:00 committed by GitHub
parent 3bf1f38b56
commit bec00cbe7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();
if (session) {
try {
const response = await getChats();
return response.reverse();
} catch (error) {
console.error(error);
publish({
variant: "danger",
text: t("errorFetching", { ns: "chat" }),
});
return response.reverse();
} catch (error) {
console.error(error);
publish({
variant: "danger",
text: t("errorFetching", { ns: "chat" }),
});
}
}
};