mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 18:52:12 +03:00
886d30cf9e
* 🚚 move june analytics to folder and update paths * ✨ set up google analytics * ✨ sent firt GA event with react-ga * 🔒️ update security headers to include vercel and google analytics * 🚚 rename Vercel Analytics * ✨ use react-ga4 instread * 💚 fix tests
48 lines
1.3 KiB
TypeScript
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/june/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,
|
|
};
|
|
};
|