@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'
55import { FiMail , FiLock , FiUser , FiLogIn , FiUserPlus , FiSun , FiMoon } from 'react-icons/fi'
66import { motion } from 'framer-motion'
77import Link from 'next/link'
8+ import Turnstile from '@marsidev/react-turnstile'
89
910export default function LoginPage ( ) {
1011 const [ email , setEmail ] = useState ( '' )
@@ -13,6 +14,7 @@ export default function LoginPage() {
1314 const [ loading , setLoading ] = useState ( false )
1415 const [ error , setError ] = useState ( '' )
1516 const [ theme , setTheme ] = useState ( 'light' )
17+ const [ captchaToken , setCaptchaToken ] = useState ( null )
1618 const router = useRouter ( )
1719
1820 useEffect ( ( ) => {
@@ -38,7 +40,8 @@ export default function LoginPage() {
3840 if ( error ) throw error
3941 router . push ( '/dashboard' )
4042 } else {
41- const { error } = await supabase . auth . signUp ( { email, password } )
43+ if ( ! captchaToken ) throw new Error ( 'Please complete captcha' )
44+ const { error } = await supabase . auth . signUp ( { email, password, options : { captchaToken } } )
4245 if ( error ) throw error
4346 alert ( 'Check your email for confirmation!' )
4447 }
@@ -135,6 +138,15 @@ export default function LoginPage() {
135138 </ div >
136139 ) }
137140
141+ { ! isLogin && (
142+ < div className = "flex justify-center" >
143+ < Turnstile
144+ siteKey = { process . env . NEXT_PUBLIC_TURNSTILE_SITE_KEY }
145+ onSuccess = { ( token ) => setCaptchaToken ( token ) }
146+ />
147+ </ div >
148+ ) }
149+
138150 < button
139151 onClick = { handleAuth }
140152 disabled = { loading }
0 commit comments