From f0ef92614da34c6e1e1e617d6a5c6bac41f8526d Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Fri, 18 Mar 2022 12:23:02 +0800 Subject: [PATCH] Fix double `email_user/confirm` due to language render Add a persistent (per session) flag to skip any actions sparked by future renders after it has already been authenticated. --- ui/page/signInVerify/view.jsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/page/signInVerify/view.jsx b/ui/page/signInVerify/view.jsx index e018f606c..a85fcadd3 100644 --- a/ui/page/signInVerify/view.jsx +++ b/ui/page/signInVerify/view.jsx @@ -14,12 +14,14 @@ type Props = { doToast: ({}) => void, }; +let authenticationCompleted = false; + function SignInVerifyPage(props: Props) { const { history: { push, location }, doToast, } = props; - const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(false); + const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(authenticationCompleted); const [showCaptchaMessage, setShowCaptchaMessage] = useState(false); const [captchaLoaded, setCaptchaLoaded] = useState(false); const urlParams = new URLSearchParams(location.search); @@ -43,10 +45,10 @@ function SignInVerifyPage(props: Props) { }, [authToken, userSubmittedEmail, verificationToken, doToast, push]); React.useEffect(() => { - if (!needsRecaptcha) { + if (!needsRecaptcha && !isAuthenticationSuccess) { verifyUser(); } - }, [needsRecaptcha]); + }, []); React.useEffect(() => { let captchaTimeout; @@ -80,6 +82,7 @@ function SignInVerifyPage(props: Props) { ...(captchaValue ? { recaptcha: captchaValue } : {}), }) .then(() => { + authenticationCompleted = true; setIsAuthenticationSuccess(true); }) .catch(() => {