@@ -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