import { resetPassword } from '@/lib/recover'

export async function POST(request: Request) {
  let token = ''
  let password = ''
  let confPassword = ''
  try {
    const body = await request.json()
    token = String(body.token ?? '')
    password = String(body.password ?? '').trim()
    confPassword = String(body.confPassword ?? '').trim()
  } catch {
    return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
  }
  if (!token) return Response.json({ success: false, error: 'invalidLink' })
  const result = await resetPassword(token, password, confPassword)
  return Response.json(result)
}
