fix: viewport metadata (Next.js 15), lazy auth client init (location SSR error), force-dynamic dashboard

This commit is contained in:
Renato
2026-07-20 18:14:06 +02:00
parent e69b18abaa
commit b15e72837f
7 changed files with 52 additions and 21 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
import type { Metadata } from "next" import type { Metadata, Viewport } from "next"
import { Inter } from "next/font/google" import { Inter } from "next/font/google"
import "./globals.css" import "./globals.css"
@@ -7,7 +7,6 @@ const inter = Inter({ subsets: ["latin"], variable: "--font-inter" })
export const metadata: Metadata = { export const metadata: Metadata = {
title: "EduEasy", title: "EduEasy",
description: "Plataforma educativa infantil", description: "Plataforma educativa infantil",
viewport: "width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover",
appleWebApp: { appleWebApp: {
capable: true, capable: true,
statusBarStyle: "default", statusBarStyle: "default",
@@ -15,6 +14,13 @@ export const metadata: Metadata = {
}, },
} }
export const viewport: Viewport = {
width: "device-width",
initialScale: 1,
maximumScale: 1,
viewportFit: "cover",
}
export default function RootLayout({ export default function RootLayout({
children, children,
}: { }: {
+9 -2
View File
@@ -2,7 +2,7 @@
import { useState } from "react" import { useState } from "react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { authClient } from "@/lib/auth-client" import { getAuth } from "@/lib/auth-client"
export default function LoginPage() { export default function LoginPage() {
const [email, setEmail] = useState("") const [email, setEmail] = useState("")
@@ -16,7 +16,14 @@ export default function LoginPage() {
setLoading(true) setLoading(true)
setError("") setError("")
const { error: err } = await authClient.signIn.email({ const auth = getAuth()
if (!auth) {
setError("Error de inicialización")
setLoading(false)
return
}
const { error: err } = await auth.signIn.email({
email, email,
password, password,
}) })
+3 -2
View File
@@ -1,7 +1,7 @@
"use client" "use client"
import { useState } from "react" import { useState } from "react"
import { authClient } from "@/lib/auth-client" import { getAuth } from "@/lib/auth-client"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { GatoMascota } from "@/components/child/gato-mascota" import { GatoMascota } from "@/components/child/gato-mascota"
@@ -10,7 +10,8 @@ export default function PairingPage() {
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [error, setError] = useState("") const [error, setError] = useState("")
const [paired, setPaired] = useState(false) const [paired, setPaired] = useState(false)
const { data: session } = authClient.useSession() const auth = getAuth()
const { data: session } = auth?.useSession() ?? { data: null }
const router = useRouter() const router = useRouter()
const handlePairing = async (e: React.FormEvent) => { const handlePairing = async (e: React.FormEvent) => {
+3 -2
View File
@@ -1,10 +1,11 @@
"use client" "use client"
import { authClient } from "@/lib/auth-client" import { getAuth } from "@/lib/auth-client"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
export default function ConfigPage() { export default function ConfigPage() {
const { data: session } = authClient.useSession() const auth = getAuth()
const { data: session } = auth?.useSession() ?? { data: null }
const router = useRouter() const router = useRouter()
return ( return (
+12 -7
View File
@@ -1,16 +1,21 @@
"use client" "use client"
import { useEffect } from "react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { authClient } from "@/lib/auth-client" import { getAuth } from "@/lib/auth-client"
export default function ParentDashboard() { export default function ParentDashboard() {
const { data: session } = authClient.useSession() const auth = getAuth()
const { data: session } = auth?.useSession() ?? { data: null }
const router = useRouter() const router = useRouter()
if (!session) { useEffect(() => {
router.push("/parent/auth/login") if (session === null) {
return null router.push("/parent/auth/login")
} }
}, [session, router])
if (!session) return null
return ( return (
<div className="min-h-dvh p-6"> <div className="min-h-dvh p-6">
@@ -22,7 +27,7 @@ export default function ParentDashboard() {
</p> </p>
</div> </div>
<button <button
onClick={() => authClient.signOut()} onClick={() => auth?.signOut()}
className="text-sm text-muted-foreground underline" className="text-sm text-muted-foreground underline"
> >
Cerrar sesión Cerrar sesión
+3 -2
View File
@@ -2,10 +2,11 @@
import { useEffect } from "react" import { useEffect } from "react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { authClient } from "@/lib/auth-client" import { getAuth } from "@/lib/auth-client"
export default function ParentPage() { export default function ParentPage() {
const { data: session, isPending } = authClient.useSession() const auth = getAuth()
const { data: session, isPending } = auth?.useSession() ?? { data: null, isPending: false }
const router = useRouter() const router = useRouter()
useEffect(() => { useEffect(() => {
+14 -4
View File
@@ -2,8 +2,18 @@
import { createAuthClient } from "better-auth/react" import { createAuthClient } from "better-auth/react"
export const authClient = createAuthClient({ let client: ReturnType<typeof createAuthClient> | null = null
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
})
export const { signIn, signUp, useSession } = authClient function initClient() {
if (typeof window === "undefined") return
if (!client) {
client = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
})
}
return client
}
export function getAuth() {
return initClient()
}