Log-in y crear cuenta: avisar si ya hay sesión en vez de ofrecer el formulario
Ninguna de las dos miraba la sesión, así que quien ya estaba conectado veía el formulario de login o el de registro. Ahora, con `bnetId` en sesión (lo mismo que da por buena la sesión en el resto del sitio), sale «¡Ya estás conectado!» y un enlace a /log-out, como las plantillas del tema. En crear cuenta el cuadro informativo se mantiene: sigue explicando cómo son las cuentas aunque ya tengas sesión. Solo se sustituye el formulario. Las dos pasan a `force-dynamic`: leen cookies y no se pueden prerenderizar. Verificado en producción sellando una cookie de sesión real con iron-session: con sesión salen los dos avisos y desaparece el formulario; sin sesión el formulario sigue ahí y el aviso no se renderiza. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||||
|
import { Link } from '@/i18n/navigation'
|
||||||
|
import { getSession } from '@/lib/session'
|
||||||
import { PageShell } from '@/components/PageShell'
|
import { PageShell } from '@/components/PageShell'
|
||||||
import { RegisterForm } from './RegisterForm'
|
import { RegisterForm } from './RegisterForm'
|
||||||
|
|
||||||
|
// Lee la sesión (cookies), así que no se puede prerenderizar.
|
||||||
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise<Metadata> {
|
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise<Metadata> {
|
||||||
const { locale } = await params
|
const { locale } = await params
|
||||||
const t = await getTranslations({ locale, namespace: 'Register' })
|
const t = await getTranslations({ locale, namespace: 'Register' })
|
||||||
@@ -13,6 +18,9 @@ export default async function CreateAccountPage({ params }: { params: Promise<{
|
|||||||
const { locale } = await params
|
const { locale } = await params
|
||||||
setRequestLocale(locale)
|
setRequestLocale(locale)
|
||||||
const t = await getTranslations('Register')
|
const t = await getTranslations('Register')
|
||||||
|
// El cuadro informativo se queda: sigue explicando cómo son las cuentas aunque
|
||||||
|
// ya tengas sesión. Lo que se sustituye es el formulario.
|
||||||
|
const session = await getSession()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell title={t('title')}>
|
<PageShell title={t('title')}>
|
||||||
@@ -31,7 +39,15 @@ export default async function CreateAccountPage({ params }: { params: Promise<{
|
|||||||
</div>
|
</div>
|
||||||
<div className="box-content">
|
<div className="box-content">
|
||||||
<div className="body-box-content centered">
|
<div className="body-box-content centered">
|
||||||
<RegisterForm />
|
{session.bnetId ? (
|
||||||
|
<>
|
||||||
|
<p>{t('alreadyLogged')}</p>
|
||||||
|
<br />
|
||||||
|
<p>{t.rich('alreadyLoggedCreate', { logout: (c) => <Link href="/log-out">{c}</Link> })}</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<RegisterForm />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</PageShell>
|
</PageShell>
|
||||||
|
|||||||
@@ -1,13 +1,34 @@
|
|||||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||||
import { Link } from '@/i18n/navigation'
|
import { Link } from '@/i18n/navigation'
|
||||||
|
import { getSession } from '@/lib/session'
|
||||||
import { PageShell } from '@/components/PageShell'
|
import { PageShell } from '@/components/PageShell'
|
||||||
import { LoginForm } from './LoginForm'
|
import { LoginForm } from './LoginForm'
|
||||||
|
|
||||||
|
// Lee la sesión (cookies), así que no se puede prerenderizar.
|
||||||
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
export default async function LoginPage({ params }: { params: Promise<{ locale: string }> }) {
|
export default async function LoginPage({ params }: { params: Promise<{ locale: string }> }) {
|
||||||
const { locale } = await params
|
const { locale } = await params
|
||||||
setRequestLocale(locale)
|
setRequestLocale(locale)
|
||||||
const t = await getTranslations('Login')
|
const t = await getTranslations('Login')
|
||||||
|
|
||||||
|
// Ya conectado: `bnetId` basta, es lo que da por buena la sesión el resto del
|
||||||
|
// sitio. Sin esto se ofrecía el formulario a quien ya tenía sesión.
|
||||||
|
const session = await getSession()
|
||||||
|
if (session.bnetId) {
|
||||||
|
return (
|
||||||
|
<PageShell title={t('title')}>
|
||||||
|
<div className="box-content">
|
||||||
|
<div className="body-box-content centered">
|
||||||
|
<p>{t('alreadyLogged')}</p>
|
||||||
|
<br />
|
||||||
|
<p>{t.rich('alreadyLoggedOther', { logout: (c) => <Link href="/log-out">{c}</Link> })}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PageShell>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageShell title={t('title')}>
|
<PageShell title={t('title')}>
|
||||||
<div className="box-content">
|
<div className="box-content">
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
},
|
},
|
||||||
"Login": {
|
"Login": {
|
||||||
"title": "Sign in to NightSpire",
|
"title": "Sign in to NightSpire",
|
||||||
|
"alreadyLogged": "You are already signed in!",
|
||||||
|
"alreadyLoggedOther": "If you want to sign in with another account, <logout>sign out</logout> first.",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"submit": "Sign in",
|
"submit": "Sign in",
|
||||||
@@ -170,6 +172,8 @@
|
|||||||
},
|
},
|
||||||
"Register": {
|
"Register": {
|
||||||
"title": "Create account",
|
"title": "Create account",
|
||||||
|
"alreadyLogged": "You are already signed in!",
|
||||||
|
"alreadyLoggedCreate": "If you want to create an account, <logout>sign out</logout> first.",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"confPassword": "Confirm password",
|
"confPassword": "Confirm password",
|
||||||
"email": "Gmail email address",
|
"email": "Gmail email address",
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
},
|
},
|
||||||
"Login": {
|
"Login": {
|
||||||
"title": "Conectar a NightSpire",
|
"title": "Conectar a NightSpire",
|
||||||
|
"alreadyLogged": "¡Ya estás conectado!",
|
||||||
|
"alreadyLoggedOther": "Si quieres conectar otra cuenta, primero <logout>desconecta</logout>.",
|
||||||
"email": "Correo electrónico",
|
"email": "Correo electrónico",
|
||||||
"password": "Contraseña",
|
"password": "Contraseña",
|
||||||
"submit": "Conectar",
|
"submit": "Conectar",
|
||||||
@@ -170,6 +172,8 @@
|
|||||||
},
|
},
|
||||||
"Register": {
|
"Register": {
|
||||||
"title": "Creación de cuenta",
|
"title": "Creación de cuenta",
|
||||||
|
"alreadyLogged": "¡Ya estás conectado!",
|
||||||
|
"alreadyLoggedCreate": "Si quieres crear una cuenta, primero <logout>desconecta</logout>.",
|
||||||
"password": "Contraseña",
|
"password": "Contraseña",
|
||||||
"confPassword": "Confirmar contraseña",
|
"confPassword": "Confirmar contraseña",
|
||||||
"email": "Correo electrónico de Gmail",
|
"email": "Correo electrónico de Gmail",
|
||||||
|
|||||||
Reference in New Issue
Block a user