Ir al contenido

Página(s) privada(s)

Una vez que el usuario está autenticado, puedes construir rutas privadas como un dashboard de usuario, una cuenta, etc.

Aquí tienes un ejemplo de un dashboard de usuario sencillo que muestra datos privados del usuario en la página:

---
import { getSession } from '@/lib/auth'
const session = getSession(Astro.request)
if (session) {
// If need to do something on the server side say fetch data for the user
// This is the right block to do it
} else {
// In case the user is not logged in
// Redirect them for example
return Astro.redirect('/')
}
---
<html>
<head> </head>
<body>
The user that's logged name is {session.user.name}
</body>
</html>