import { activateAccount } from '@/lib/register'

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

  const ip = (request.headers.get('x-forwarded-for') || '0.0.0.0').split(',')[0].trim()
  const result = await activateAccount(hash, ip)
  return Response.json(result)
}
