Skip to content

Commit e319437

Browse files
authored
Merge pull request #27 from Sohan-Rout/main1
Fix : added captcha
2 parents 889a4df + 63925e2 commit e319437

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

app/login/page.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'
55
import { FiMail, FiLock, FiUser, FiLogIn, FiUserPlus, FiSun, FiMoon } from 'react-icons/fi'
66
import { motion } from 'framer-motion'
77
import Link from 'next/link'
8+
import Turnstile from '@marsidev/react-turnstile'
89

910
export 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}

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@gsap/react": "^2.1.2",
14+
"@marsidev/react-turnstile": "^1.3.0",
1415
"@monaco-editor/react": "^4.7.0",
1516
"@supabase/auth-helpers-nextjs": "^0.10.0",
1617
"@supabase/ssr": "^0.6.1",

0 commit comments

Comments
 (0)