|
|
|
@ -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]); |
|
|
|
|
|
|
|
|