Login: navegación completa tras autenticar (cabecera no se actualizaba)
Con router.push el layout persiste entre rutas, así que la cabecera seguía
mostrando "Conectar/Crear cuenta" tras el login hasta recargar. Ahora login y
select-account hacen window.location.assign(/{locale}/...) para que el servidor
re-renderice el layout/cabecera con la sesión nueva.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useRouter } from '@/i18n/navigation'
|
||||
import { useTranslations, useLocale } from 'next-intl'
|
||||
import { Turnstile } from '@/components/Turnstile'
|
||||
|
||||
const ERROR_KEYS = ['invalidCredentials', 'missingFields', 'invalidRequest', 'captchaFailed'] as const
|
||||
|
||||
export function LoginForm() {
|
||||
const t = useTranslations('Login')
|
||||
const router = useRouter()
|
||||
const locale = useLocale()
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [showPw, setShowPw] = useState(false)
|
||||
@@ -36,7 +35,11 @@ export function LoginForm() {
|
||||
const data: { success?: boolean; needsSelection?: boolean; error?: string } = await res.json()
|
||||
if (data.success) {
|
||||
setMessage({ ok: true, text: t('success') })
|
||||
router.push(data.needsSelection ? '/select-account' : '/my-account')
|
||||
// Navegación completa (no del lado cliente): fuerza que el servidor
|
||||
// re-renderice el layout/cabecera con la sesión nueva. Con router.push
|
||||
// el layout persiste y la cabecera seguía mostrando "Conectar".
|
||||
window.location.assign(`/${locale}${data.needsSelection ? '/select-account' : '/my-account'}`)
|
||||
return
|
||||
} else {
|
||||
const key = (ERROR_KEYS as readonly string[]).includes(data.error ?? '') ? data.error! : 'genericError'
|
||||
setMessage({ ok: false, text: t(key) })
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useRouter } from '@/i18n/navigation'
|
||||
import { useTranslations, useLocale } from 'next-intl'
|
||||
|
||||
interface GameAccount {
|
||||
id: number
|
||||
@@ -11,7 +10,7 @@ interface GameAccount {
|
||||
|
||||
export function SelectAccountForm({ accounts }: { accounts: GameAccount[] }) {
|
||||
const t = useTranslations('SelectAccount')
|
||||
const router = useRouter()
|
||||
const locale = useLocale()
|
||||
const [busy, setBusy] = useState<number | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
@@ -27,7 +26,8 @@ export function SelectAccountForm({ accounts }: { accounts: GameAccount[] }) {
|
||||
body: JSON.stringify({ accountId: id }),
|
||||
})
|
||||
const data: { success?: boolean } = await res.json()
|
||||
if (data.success) router.push('/my-account')
|
||||
// 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)
|
||||
|
||||
Reference in New Issue
Block a user