show refresh message if the captcha hasn't loaded after 2 seconds
This commit is contained in:
parent
8e89a144cf
commit
56eeca76a5
1 changed files with 36 additions and 0 deletions
|
@ -3,7 +3,9 @@ import React, { useState } from 'react';
|
||||||
import { withRouter } from 'react-router';
|
import { withRouter } from 'react-router';
|
||||||
import Page from 'component/page';
|
import Page from 'component/page';
|
||||||
import ReCAPTCHA from 'react-google-recaptcha';
|
import ReCAPTCHA from 'react-google-recaptcha';
|
||||||
|
import Button from 'component/button';
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
|
import I18nMessage from 'component/i18nMessage';
|
||||||
import * as PAGES from 'constants/pages';
|
import * as PAGES from 'constants/pages';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -17,6 +19,8 @@ function SignInVerifyPage(props: Props) {
|
||||||
doToast,
|
doToast,
|
||||||
} = props;
|
} = props;
|
||||||
const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(false);
|
const [isAuthenticationSuccess, setIsAuthenticationSuccess] = useState(false);
|
||||||
|
const [showCaptchaMessage, setShowCaptchaMessage] = useState(false);
|
||||||
|
const [captchaLoaded, setCaptchaLoaded] = useState(false);
|
||||||
const urlParams = new URLSearchParams(location.search);
|
const urlParams = new URLSearchParams(location.search);
|
||||||
const authToken = urlParams.get('auth_token');
|
const authToken = urlParams.get('auth_token');
|
||||||
const userSubmittedEmail = urlParams.get('email');
|
const userSubmittedEmail = urlParams.get('email');
|
||||||
|
@ -43,10 +47,30 @@ function SignInVerifyPage(props: Props) {
|
||||||
}
|
}
|
||||||
}, [needsRecaptcha]);
|
}, [needsRecaptcha]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
let captchaTimeout;
|
||||||
|
|
||||||
|
if (needsRecaptcha && !captchaLoaded) {
|
||||||
|
captchaTimeout = setTimeout(() => {
|
||||||
|
setShowCaptchaMessage(true);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (captchaTimeout) {
|
||||||
|
clearTimeout(captchaTimeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [needsRecaptcha, captchaLoaded]);
|
||||||
|
|
||||||
function onCaptchaChange(value) {
|
function onCaptchaChange(value) {
|
||||||
verifyUser(value);
|
verifyUser(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCaptchaReady() {
|
||||||
|
setCaptchaLoaded(true);
|
||||||
|
}
|
||||||
|
|
||||||
function verifyUser(captchaValue) {
|
function verifyUser(captchaValue) {
|
||||||
Lbryio.call('user_email', 'confirm', {
|
Lbryio.call('user_email', 'confirm', {
|
||||||
auth_token: authToken,
|
auth_token: authToken,
|
||||||
|
@ -75,11 +99,23 @@ function SignInVerifyPage(props: Props) {
|
||||||
? __('Click below to sign in to lbry.tv')
|
? __('Click below to sign in to lbry.tv')
|
||||||
: __('Welcome back! You are automatically being signed in.')}
|
: __('Welcome back! You are automatically being signed in.')}
|
||||||
</p>
|
</p>
|
||||||
|
<p className="section__subtitle">
|
||||||
|
{showCaptchaMessage && !isAuthenticationSuccess && (
|
||||||
|
<I18nMessage
|
||||||
|
tokens={{
|
||||||
|
refresh: <Button button="link" label={__('refreshing')} onClick={() => window.location.reload()} />,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Not seeing a captcha? Check your ad blocker or try %refresh%.
|
||||||
|
</I18nMessage>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
{!isAuthenticationSuccess && needsRecaptcha && (
|
{!isAuthenticationSuccess && needsRecaptcha && (
|
||||||
<div className="section__actions">
|
<div className="section__actions">
|
||||||
<ReCAPTCHA
|
<ReCAPTCHA
|
||||||
sitekey="6LePsJgUAAAAAFTuWOKRLnyoNKhm0HA4C3elrFMG"
|
sitekey="6LePsJgUAAAAAFTuWOKRLnyoNKhm0HA4C3elrFMG"
|
||||||
onChange={onCaptchaChange}
|
onChange={onCaptchaChange}
|
||||||
|
asyncScriptOnLoad={onCaptchaReady}
|
||||||
onExpired={onAuthError}
|
onExpired={onAuthError}
|
||||||
onErrored={onAuthError}
|
onErrored={onAuthError}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue