import { confirmNewEmail } from '@/lib/change-email'

export async function POST(request: Request) {
  let hash = ''
  try {
    const b = await request.json()
    hash = String(b.hash ?? '')
  } catch {
    return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
  }
  if (!hash) return Response.json({ success: false, error: 'invalidLink' })
  return Response.json(await confirmNewEmail(hash))
}
