From 441ce2daca265de33bf7bb4287ad2968ebc36faa Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sat, 7 Jun 2025 02:09:44 +0200 Subject: [PATCH] feat: redirection after verification --- web/src/layout/VerificationLayout.tsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/web/src/layout/VerificationLayout.tsx b/web/src/layout/VerificationLayout.tsx index 9292487..8403090 100644 --- a/web/src/layout/VerificationLayout.tsx +++ b/web/src/layout/VerificationLayout.tsx @@ -3,7 +3,7 @@ import { useAuth } from "@/store/auth"; import { useVerify } from "@/store/verify"; import { Eye, MailCheck, ScanFace } from "lucide-react"; import { useEffect, type FC } from "react"; -import { Navigate, Outlet, useLocation } from "react-router"; +import { Navigate, Outlet, useLocation, useNavigate } from "react-router"; const steps = [ { @@ -33,10 +33,27 @@ const VerificationLayout: FC = () => { const step = useVerify((s) => s.step); const loadStep = useVerify((s) => s.loadStep); + const redirect = useVerify((s) => s.redirect); + const setRedirect = useVerify((s) => s.setRedirect); + + const navigate = useNavigate(); + useEffect(() => { if (profile) loadStep(profile); }, [loadStep, profile]); + useEffect(() => { + if (location.state?.from) { + setRedirect(location.state.from); + } + }, [location.state?.from, setRedirect]); + + useEffect(() => { + if (step === false) { + navigate(redirect ?? "/", { state: { reset: true } }); + } + }, [navigate, redirect, step]); + if (step === "email" && !location.pathname.startsWith("/verify/email")) { return ; } @@ -53,7 +70,9 @@ const VerificationLayout: FC = () => {
{location.pathname.replace(/\/$/i, "") !== "/verify" && - step != null && } + typeof step === "string" && ( + + )}