import { Button } from "@/components/ui/button"; import { Card, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { useUserContext } from "@/context/user-context"; import { useMutation } from "@tanstack/react-query"; import axios from "axios"; import { useEffect, useRef } from "react"; import { Trans, useTranslation } from "react-i18next"; import { Navigate } from "react-router"; import { toast } from "sonner"; export const LogoutPage = () => { const { provider, username, isLoggedIn, email, oauthName } = useUserContext(); const { t } = useTranslation(); const redirectTimer = useRef(null); const logoutMutation = useMutation({ mutationFn: () => axios.post("/api/user/logout"), mutationKey: ["logout"], onSuccess: () => { toast.success(t("logoutSuccessTitle"), { description: t("logoutSuccessSubtitle"), }); redirectTimer.current = window.setTimeout(() => { window.location.assign("/login"); }, 500); }, onError: () => { toast.error(t("logoutFailTitle"), { description: t("logoutFailSubtitle"), }); }, }); useEffect( () => () => { if (redirectTimer.current) clearTimeout(redirectTimer.current); }, [], ); if (!isLoggedIn) { return ; } return ( {t("logoutTitle")} {provider !== "username" ? ( , }} values={{ username: email, provider: oauthName, }} /> ) : ( , }} values={{ username, }} /> )} ); };