From e266a1dfdd60e1744cf257c8a41f756eb22c4872 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Sat, 16 May 2026 12:44:17 +0330 Subject: [PATCH] feat: enhance redirect logic in Intro component with ref and listener for improved flow --- src/app/intro/page.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/app/intro/page.tsx b/src/app/intro/page.tsx index bc5a9e9..7fd085a 100644 --- a/src/app/intro/page.tsx +++ b/src/app/intro/page.tsx @@ -1,7 +1,7 @@ "use client"; import Image from "next/image"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useRouter } from "next/navigation"; import Button from "@/components/ui/button"; import NavigationButton from "@/components/ui/navigation-button"; @@ -47,11 +47,16 @@ export default function Intro() { const [isReportSheetOpen, setIsReportSheetOpen] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [isCheckingRedirect, setIsCheckingRedirect] = useState(true); + const isRedirectingRef = useRef(false); useEffect(() => { let isCancelled = false; const redirectIfNeeded = async () => { + if (isRedirectingRef.current) { + return; + } + const shouldRedirect = authBridge.isAuthenticated() && window.sessionStorage.getItem(REDIRECT_SESSION_KEY) === "true"; @@ -63,19 +68,35 @@ export default function Intro() { return; } + isRedirectingRef.current = true; + + if (!isCancelled) { + setIsCheckingRedirect(true); + } + const profileResponse = profile ?? (await refetch()).data; const nextPath = localizePath(getSubmitPath(profileResponse), locale); window.sessionStorage.removeItem(REDIRECT_SESSION_KEY); if (!isCancelled) { router.replace(nextPath); + return; } + + isRedirectingRef.current = false; }; void redirectIfNeeded(); + const unsubscribe = window.addFlutterResponseListener?.((event) => { + if (event.action === "login" && event.success) { + void redirectIfNeeded(); + } + }); + return () => { isCancelled = true; + unsubscribe?.(); }; }, [locale, profile, refetch, router]);