mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-03 23:55:44 +00:00 
			
		
		
		
	feat: invalid domain warning (#332)
* wip * refactor: update domain warning layout * i18n: add domain warning translations * refactor: rework hooks usage * feat: clear timeouts * fix: use useeffect to cleanup timeout * refactor: rework redirects and history storage * refactor: rename domain to root domain
This commit is contained in:
		@@ -11,20 +11,18 @@ import { useUserContext } from "@/context/user-context";
 | 
			
		||||
import { capitalize } from "@/lib/utils";
 | 
			
		||||
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 } = useUserContext();
 | 
			
		||||
 | 
			
		||||
  if (!isLoggedIn) {
 | 
			
		||||
    return <Navigate to="/login" />;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const { genericName } = useAppContext();
 | 
			
		||||
  const { t } = useTranslation();
 | 
			
		||||
 | 
			
		||||
  const redirectTimer = useRef<number | null>(null);
 | 
			
		||||
 | 
			
		||||
  const logoutMutation = useMutation({
 | 
			
		||||
    mutationFn: () => axios.post("/api/user/logout"),
 | 
			
		||||
    mutationKey: ["logout"],
 | 
			
		||||
@@ -33,8 +31,8 @@ export const LogoutPage = () => {
 | 
			
		||||
        description: t("logoutSuccessSubtitle"),
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      setTimeout(async () => {
 | 
			
		||||
        window.location.replace("/login");
 | 
			
		||||
      redirectTimer.current = window.setTimeout(() => {
 | 
			
		||||
        window.location.assign("/login");
 | 
			
		||||
      }, 500);
 | 
			
		||||
    },
 | 
			
		||||
    onError: () => {
 | 
			
		||||
@@ -44,6 +42,17 @@ export const LogoutPage = () => {
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  useEffect(
 | 
			
		||||
    () => () => {
 | 
			
		||||
      if (redirectTimer.current) clearTimeout(redirectTimer.current);
 | 
			
		||||
    },
 | 
			
		||||
    [],
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  if (!isLoggedIn) {
 | 
			
		||||
    return <Navigate to="/login" replace />;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Card className="min-w-xs sm:min-w-sm">
 | 
			
		||||
      <CardHeader>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user