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.
This commit is contained in:
infinite-persistence 2022-03-18 12:23:02 +08:00 committed by Thomas Zarebczan
parent fdb5658df6
commit f0ef92614d

View file

@ -14,12 +14,14 @@ type Props = {
doToast: ({}) => void, doToast: ({}) => void,
}; };
let authenticationCompleted = false;
function SignInVerifyPage(props: Props) { function SignInVerifyPage(props: Props) {
const { const {
history: { push, location }, history: { push, location },
doToast, doToast,
} = props; } = props;
const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(false); const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(authenticationCompleted);
const [showCaptchaMessage, setShowCaptchaMessage] = useState(false); const [showCaptchaMessage, setShowCaptchaMessage] = useState(false);
const [captchaLoaded, setCaptchaLoaded] = useState(false); const [captchaLoaded, setCaptchaLoaded] = useState(false);
const urlParams = new URLSearchParams(location.search); const urlParams = new URLSearchParams(location.search);
@ -43,10 +45,10 @@ function SignInVerifyPage(props: Props) {
}, [authToken, userSubmittedEmail, verificationToken, doToast, push]); }, [authToken, userSubmittedEmail, verificationToken, doToast, push]);
React.useEffect(() => { React.useEffect(() => {
if (!needsRecaptcha) { if (!needsRecaptcha && !isAuthenticationSuccess) {
verifyUser(); verifyUser();
} }
}, [needsRecaptcha]); }, []);
React.useEffect(() => { React.useEffect(() => {
let captchaTimeout; let captchaTimeout;
@ -80,6 +82,7 @@ function SignInVerifyPage(props: Props) {
...(captchaValue ? { recaptcha: captchaValue } : {}), ...(captchaValue ? { recaptcha: captchaValue } : {}),
}) })
.then(() => { .then(() => {
authenticationCompleted = true;
setIsAuthenticationSuccess(true); setIsAuthenticationSuccess(true);
}) })
.catch(() => { .catch(() => {