Skip to content

Commit d779e9f

Browse files
committed
Fix : added login page edits
1 parent 627b045 commit d779e9f

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

app/api/auth/route.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ export async function POST(req) {
4343
}
4444

4545
else if (action === 'login') {
46-
// Authenticate user using Supabase admin API (signInWithPassword)
47-
const { data, error } = await supabase.auth.admin.signInWithPassword({ email, password })
48-
if (error) {
49-
return new Response(JSON.stringify({ success: false, message: error.message }), { status: 400 })
50-
}
51-
return new Response(JSON.stringify({ success: true, message: 'Login successful.' }), { status: 200 })
46+
// For login, only verify captcha and return success.
47+
return new Response(JSON.stringify({ success: true, message: 'Captcha verified. You can now login using email/password.' }), { status: 200 })
5248
}
5349

5450
// Invalid action

app/login/page.jsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,30 @@ export default function LoginPage() {
4242
try {
4343
if (!captchaToken) throw new Error('Please complete captcha')
4444

45-
const res = await fetch('/auth', {
46-
method: 'POST',
47-
headers: { 'Content-Type': 'application/json' },
48-
body: JSON.stringify({
49-
email,
50-
password,
51-
captchaToken,
52-
action: isLogin ? 'login' : 'signup'
53-
}),
54-
})
55-
56-
const data = await res.json()
57-
if (!data.success) throw new Error(data.message || 'Action failed')
58-
5945
if (isLogin) {
46+
// Verify captcha first via API route
47+
const verifyRes = await fetch('/auth', {
48+
method: 'POST',
49+
headers: { 'Content-Type': 'application/json' },
50+
body: JSON.stringify({ email, password, captchaToken, action: 'login' }),
51+
})
52+
const verifyData = await verifyRes.json()
53+
if (!verifyData.success) throw new Error(verifyData.message || 'Captcha verification failed')
54+
55+
// After captcha verified, login using frontend anon key
56+
const { error } = await supabase.auth.signInWithPassword({ email, password })
57+
if (error) throw error
58+
6059
router.push('/dashboard')
6160
} else {
61+
// Signup flow remains the same
62+
const res = await fetch('/auth', {
63+
method: 'POST',
64+
headers: { 'Content-Type': 'application/json' },
65+
body: JSON.stringify({ email, password, captchaToken, action: 'signup' }),
66+
})
67+
const data = await res.json()
68+
if (!data.success) throw new Error(data.message || 'Signup failed')
6269
alert(data.message)
6370
setIsLogin(true)
6471
}

0 commit comments

Comments
 (0)