434011624c
trailingSlash true ponía barra en todo (/es/content-creators/). Se pasa a skipTrailingSlashRedirect + normalización en middleware: raíz de idioma /es → /es/ (con barra), y cualquier sub-ruta con barra final se redirige sin ella (/es/x/ → /es/x). Sin bucles. Las /api quedan fuera del middleware (sin 308). El redirect del logout apunta a /es/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useTranslations, useLocale } from 'next-intl'
|
|
|
|
interface GameAccount {
|
|
id: number
|
|
username: string
|
|
label: string // nombre visible: «15#1» → «WOW1»
|
|
}
|
|
|
|
export function SelectAccountForm({ accounts }: { accounts: GameAccount[] }) {
|
|
const t = useTranslations('SelectAccount')
|
|
const locale = useLocale()
|
|
const [busy, setBusy] = useState<number | null>(null)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
async function select(id: number) {
|
|
if (busy !== null) return
|
|
setBusy(id)
|
|
setError(null)
|
|
try {
|
|
const res = await fetch('/api/auth/select-account', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify({ accountId: id }),
|
|
})
|
|
const data: { success?: boolean } = await res.json()
|
|
// Navegación completa: re-renderiza el layout/cabecera con la cuenta ya elegida.
|
|
if (data.success) window.location.assign(`/${locale}/my-account`)
|
|
else {
|
|
setError(t('error'))
|
|
setBusy(null)
|
|
}
|
|
} catch {
|
|
setError(t('error'))
|
|
setBusy(null)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="centered">
|
|
<table className="middle-center-table">
|
|
<tbody>
|
|
{accounts.map((a) => (
|
|
<tr key={a.id}>
|
|
<td>
|
|
<button
|
|
onClick={() => select(a.id)}
|
|
disabled={busy !== null}
|
|
className="login-button"
|
|
>
|
|
{busy === a.id ? t('entering') : a.label}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<div className="alert-message" style={{ display: error ? 'block' : 'none' }}>
|
|
{error && <span className="red-form-response">{error}</span>}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|