Skip to content

Commit

Permalink
Revert captcha removal #2839
Browse files Browse the repository at this point in the history
  • Loading branch information
millianapia committed Mar 4, 2025
1 parent 06a45e2 commit 42d2645
Showing 1 changed file with 14 additions and 36 deletions.
50 changes: 14 additions & 36 deletions web/pages/api/subscribe-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,19 @@ import { signUp } from './subscription'
import { NextApiRequest, NextApiResponse } from 'next'
import { validateFormRequest } from './forms/validateFormRequest'

export default async function handler(
req: { body: { subscribeFormParamers: any; frcCaptchaSolution: any }; method: string },
res: {
status: (arg0: number) => {
(): any
new (): any
json: { (arg0: { error?: any; msg?: string }): any; new (): any }
}
},
) {
console.log('📥 API received request with:', req.body)

if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method Not Allowed' })
}

const { subscribeFormParamers, frcCaptchaSolution } = req.body

// 🛑 Check if subscribeFormParamers is undefined
if (!subscribeFormParamers || !subscribeFormParamers.email) {
console.error('❌ Missing or invalid subscribeFormParamers:', subscribeFormParamers)
return res.status(400).json({ msg: 'Invalid request data' })
}

console.log('✅ Valid request data:', subscribeFormParamers)

try {
const success = await signUp(subscribeFormParamers)
if (!success) throw new Error('Subscription failed')

return res.status(200).json({ msg: 'Subscription successful' })
} catch (error) {
console.error('❌ Error in signUp:', (error as Error).message)
return res.status(500).json({ msg: 'Subscription failed', error: (error as Error).message })
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const result = await validateFormRequest(req, 'subscribe form')
if (result.status !== 200) {
return res.status(result.status).json({ msg: result.message })
}
const data = req.body
await signUp(data.subscribeFormParamers)
.then((isSuccessful) => {
if (!isSuccessful) {
res.status(500).json({ msg: 'Subscribe failed' })
} else res.status(200).json({ msg: 'Successfully subscribed.' })
})
.catch((error) => {
res.status(500).json({ msg: `Subscribe failed ${error}` })
})
}


0 comments on commit 42d2645

Please sign in to comment.