Skip to content

Commit 7770a2d

Browse files
committed
feat(app): add Cloudflare Turnstile widget for sign-in and sign-up pages
1 parent d21b0d0 commit 7770a2d

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/app/(uc)/signin/page.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { isEmpty } from '@/utils';
3030
import { wrapOnChange } from '@/utils/form';
3131

3232
import { getOauthSourceFromParams } from '#/domain/auth/helper';
33+
import HumanProofWidget from '#/domain/auth/widgets/human-proof';
3334
import { signin, emailCodeLogin } from '#/services/auth';
3435

3536
import LoginTypeSwitcher from './LoginTypeSwitcher';
@@ -44,6 +45,7 @@ export default function Login() {
4445
const emailFieldName = 'Email';
4546
const searchParams = useSearchParams();
4647
const [loading, setLoading] = useState(false);
48+
const [humanVerified, setHumanVerified] = useState(false);
4749
const [passwordType, setPasswordType] = useState('password');
4850
const [loginType, setLoginType] = useState('verifyCode');
4951

@@ -155,6 +157,7 @@ export default function Login() {
155157
<button
156158
type="submit"
157159
disabled={
160+
!humanVerified ||
158161
!watchAllFields.Email ||
159162
(loginType === 'password' && !watchAllFields.Password) ||
160163
(loginType === 'verifyCode' && !watchAllFields.VerifyCode) ||
@@ -166,20 +169,18 @@ export default function Login() {
166169
<span>Continue</span>
167170
</button>
168171
</form>
169-
172+
<HumanProofWidget onVerify={setHumanVerified} />
170173
{!isEmpty(errors) && watchAllFields.Email !== '' && (
171174
<p className="mt-4 text-xs text-center text-red">
172175
{loginType === 'password'
173176
? 'The email or password is wrong.'
174177
: 'The email or code is wrong.'}
175178
</p>
176179
)}
177-
178180
<LoginTypeSwitcher
179181
loginType={loginType}
180182
handleChangeLoginType={handleChangeLoginType}
181183
/>
182-
183184
{loginType == 'password' && (
184185
<div className="mt-6 text-center">
185186
Forget your password?&nbsp;

src/app/(uc)/signup/page.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useAccount } from 'wagmi';
3030
import { EyeIcon, EyeSlashIcon } from '@/components/icon/outlined';
3131
import Loader from '@/components/Loader';
3232

33+
import HumanProofWidget from '#/domain/auth/widgets/human-proof';
3334
import { registerEmail, sendCode } from '#/services/auth';
3435

3536
import { NavButtonStyle } from '../signin/page';
@@ -40,6 +41,7 @@ export default function SignUp() {
4041
const router = useRouter();
4142
const [cdMss, setCdMss] = useState(0);
4243
const [loading, setLoading] = useState(false);
44+
const [humanVerified, setHumanVerified] = useState(false);
4345
const { address } = useAccount();
4446
const searchParams = useSearchParams();
4547
const [sendLoading, setSendLoading] = useState(false);
@@ -149,6 +151,7 @@ export default function SignUp() {
149151
<button
150152
type="submit"
151153
disabled={
154+
!humanVerified ||
152155
watchAllFields.Email === '' ||
153156
watchAllFields.ConfirmPassword === '' ||
154157
watchAllFields.VerificationCode === '' ||
@@ -166,7 +169,7 @@ export default function SignUp() {
166169
{watchAllFields.ConfirmPassword !== watchAllFields.Password && (
167170
<p className="mt-4 text-center text-xs text-red">The passwords entered twice are inconsistent</p>
168171
)}
169-
172+
<HumanProofWidget onVerify={setHumanVerified} />
170173
<div className="mt-6 text-center">
171174
Already have an account?&nbsp;
172175
<span

src/app/oauth/page.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import Logo from 'public/images/svg/logo-black.svg';
2323
import { useEffect, useState } from 'react';
2424

2525
import { Button } from '@/components/Button';
26-
import CloudflareTurnstile from '@/components/control/cf-turnstile';
2726
import { SvgIcon } from '@/components/Image';
2827
import Loader from '@/components/Loader';
2928
import useMounted from '@/hooks/useMounted';
3029
import { getCopyrightText } from '@/utils/app';
3130

3231
import { setOauthSource } from '#/domain/auth/helper';
3332
import { fetchOauthClientInfo, fetchOauthClientCode } from '#/domain/auth/repository';
33+
import HumanProofWidget from '#/domain/auth/widgets/human-proof';
3434

3535
import Link from './Link';
3636
import NoteItem from './NoteItem';
@@ -133,7 +133,7 @@ export default function Page() {
133133
<NoteItem icon="international" title="Public data only" description="Limited access to your public data" />
134134
</div>
135135
<div className="mx-[-24px] p-6 border-y border-gray-600">
136-
<CloudflareTurnstile className="mb-2" onVerify={handleVerify} />
136+
<HumanProofWidget className="mb-2" onVerify={handleVerify} />
137137
<div className="flex gap-3">
138138
<Button variant="outlined" className="flex-1" onClick={handleCancel}>
139139
Cancel

src/shared/components/control/cf-turnstile/CloudflareTurnstile.js src/domain/auth/widgets/human-proof/HumanProof.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import Script from 'next/script';
1818

19-
import { isFunction } from '../../../utils';
19+
import { isFunction } from '../../../../shared/utils';
2020

2121
const sitekey = process.env.NEXT_PUBLIC_TURNSTILE_SITEKEY;
2222

23-
function CloudflareTurnstile({ className, onVerify }) {
23+
function HumanProof({ className, onVerify }) {
2424
const handleScriptLoad = () => {
2525
window.turnstile.render('#cfTurnstile', {
2626
sitekey,
@@ -40,4 +40,4 @@ function CloudflareTurnstile({ className, onVerify }) {
4040
);
4141
};
4242

43-
export default CloudflareTurnstile;
43+
export default HumanProof;

src/shared/components/control/cf-turnstile/index.js src/domain/auth/widgets/human-proof/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
* limitations under the License.
1515
*/
1616

17-
export { default } from './CloudflareTurnstile';
17+
export { default } from './HumanProof';

0 commit comments

Comments
 (0)