cceab26999
- lib/change-email.ts: requestEmailChange (valida pass/email/token, crea activación con old_email/old_email_hash, email al correo actual), confirmOldEmail (marca is_used, email al nuevo), confirmNewEmail (re-deriva verifier con el nuevo email + actualiza battlenet_accounts y account; borra la activación). - components/ConfirmClient.tsx: cliente genérico que confirma un hash por POST al abrir. - Routes /api/account/change-email, /confirm-old-email, /confirm-new-email. - Páginas /change-email (protegida) y /confirm-old-email, /confirm-new-email (auto). - Catálogos ChangeEmail, ConfirmOldEmail, ConfirmNewEmail. Verificado: change-email protegida (401/redirect), confirmaciones con hash inválido -> invalidLink sin crash. AUTH 100% reimplementado en Next.js. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { Link } from '@/i18n/navigation'
|
|
|
|
/** Cliente genérico que confirma un hash contra un endpoint (POST) al abrir la página. */
|
|
export function ConfirmClient({
|
|
hash,
|
|
endpoint,
|
|
namespace,
|
|
showLogin = false,
|
|
}: {
|
|
hash: string
|
|
endpoint: string
|
|
namespace: string
|
|
showLogin?: boolean
|
|
}) {
|
|
const t = useTranslations(namespace)
|
|
const [state, setState] = useState<'loading' | 'ok' | 'error'>('loading')
|
|
const ran = useRef(false)
|
|
|
|
useEffect(() => {
|
|
if (ran.current) return
|
|
ran.current = true
|
|
if (!hash) {
|
|
setState('error')
|
|
return
|
|
}
|
|
fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ hash }),
|
|
})
|
|
.then((r) => r.json())
|
|
.then((d: { success?: boolean }) => setState(d.success ? 'ok' : 'error'))
|
|
.catch(() => setState('error'))
|
|
}, [hash, endpoint])
|
|
|
|
return (
|
|
<div className="text-center">
|
|
{state === 'loading' && <p>{t('activating')}</p>}
|
|
{state === 'ok' && (
|
|
<>
|
|
<p className="text-green-400">{t('success')}</p>
|
|
{showLogin && (
|
|
<p className="mt-4">
|
|
<Link href="/login" className="text-sky-400 underline">
|
|
{t('goLogin')}
|
|
</Link>
|
|
</p>
|
|
)}
|
|
</>
|
|
)}
|
|
{state === 'error' && <p className="text-red-400">{t('error')}</p>}
|
|
</div>
|
|
)
|
|
}
|