1
1
"use client" ;
2
2
import Link from "next/link" ;
3
- import { useState } from "react" ;
3
+ import { useState , useRef } from "react" ;
4
4
import { signinWithOAuth } from "@/app/(auth)/actions" ;
5
5
import { AdminUserAttributes , Provider } from "@supabase/supabase-js" ;
6
6
import { zodResolver } from "@hookform/resolvers/zod" ;
@@ -22,9 +22,12 @@ import { useRouter } from "next/navigation";
22
22
import { Label } from "@/components/ui/label" ;
23
23
import { Checkbox } from "@/components/ui/checkbox" ;
24
24
import { useToggle } from "@/hooks/useToggle" ;
25
+ import HCaptcha from "@hcaptcha/react-hcaptcha" ;
25
26
26
27
export default function SignUp ( ) {
27
28
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
29
+ const [ captchaToken , setCaptchaToken ] = useState < string | null > ( null ) ;
30
+ const captcha = useRef < HCaptcha > ( null ) ;
28
31
const form = useForm < SignUpFormData > ( {
29
32
resolver : zodResolver ( signUpSchema ) ,
30
33
defaultValues : {
@@ -42,14 +45,20 @@ export default function SignUp() {
42
45
setIsSubmitting ( true ) ;
43
46
44
47
try {
45
- const formData : AdminUserAttributes = {
48
+ if ( ! captchaToken ) {
49
+ toast . error ( "Please complete the captcha challenge" ) ;
50
+ return ;
51
+ }
52
+
53
+ const formData = {
46
54
email : data . email ,
47
55
password : data . password ,
48
56
user_metadata : {
49
57
full_name : data . full_name ,
50
58
company_name : data . company_name ,
51
59
heard_about_us : data . heard_about_us ,
52
60
} ,
61
+ captchaToken : captchaToken ,
53
62
} ;
54
63
const response = await fetch ( "/api/signup" , {
55
64
method : "POST" ,
@@ -73,6 +82,8 @@ export default function SignUp() {
73
82
toast . error ( "An unexpected error occurred. Please try again." ) ;
74
83
} finally {
75
84
setIsSubmitting ( false ) ;
85
+ captcha . current ?. resetCaptcha ( ) ;
86
+ setCaptchaToken ( null ) ;
76
87
}
77
88
} ;
78
89
@@ -252,6 +263,14 @@ export default function SignUp() {
252
263
) }
253
264
/>
254
265
266
+ < HCaptcha
267
+ ref = { captcha }
268
+ sitekey = "fa6c8c52-7694-45b0-97ec-7814072256b4"
269
+ onVerify = { ( token ) => {
270
+ setCaptchaToken ( token ) ;
271
+ } }
272
+ />
273
+
255
274
< div className = "text-center text-sm text-gray-600" >
256
275
< Link
257
276
href = "/privacy"
0 commit comments