quivr/frontend/app/(auth)/logout/hooks/useLogout.ts
Mamadou DICKO b0514d6149
fix(i18n): update tests for french and spanish (#878)
* add libraries for traslation purposes

* Add button and service for language selection

* add spanish translation on login page

* add spanish translation on upload page

* Add spanish translations for explore page

* Add translations on user page

* Add translations for config page

* Add spanish translations on chat page

* add translations for brain page

* fix GUI and save on local storage

* fix (i18n) init and types

* fix (i18n): typos

* add translation on new brain modal

* add translations on metadata

* Add translations on home page

* fixes types

* fix(frontend-tests): use get by id instead of text

---------

Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
2023-08-07 14:13:41 +02:00

48 lines
1.3 KiB
TypeScript

import { useRouter } from "next/navigation";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useSupabase } from "@/lib/context/SupabaseProvider";
import { useToast } from "@/lib/hooks";
import { useEventTracking } from "@/services/analytics/useEventTracking";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useLogout = () => {
const { supabase } = useSupabase();
const [isPending, setIsPending] = useState(false);
const { track } = useEventTracking();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {t, i18n} = useTranslation(["translation","logout"]);
const { publish } = useToast();
const router = useRouter();
const handleLogout = async () => {
setIsPending(true);
const { error } = await supabase.auth.signOut();
void track("LOGOUT");
localStorage.clear();
if (error) {
console.error("Error logging out:", error.message);
publish({
variant: "danger",
text: t("error", { errorMessage: error.message, ns: "logout"}),
});
} else {
publish({
variant: "success",
text: t("loggedOut", {ns : "logout"})
});
router.replace("/");
}
setIsPending(false);
};
return {
handleLogout,
isPending,
};
};