---
title: "Página(s) privada(s)"
description: "¿Cómo crear páginas que solo sean visibles para usuarios que han iniciado sesión con LaunchFa.st?"
source: "https://www.launchfa.st/es/documentation/tutorials/private-page"
---

> **Site index for agents**
> Fetch https://www.launchfa.st/llms.txt to discover every page on this site.
> Every page is also available as Markdown by appending `.md` to its URL.

import { Tabs, TabItem } from '@astrojs/starlight/components'

Una vez que [el usuario está autenticado](/documentation/authentication), puedes construir rutas privadas como un dashboard de usuario, una cuenta, etc.

:::tip
Si quieres hacer llamadas a API protegidas, sigue [este tutorial](/documentation/tutorials/api-call#protected-api-routes).
:::

<Tabs>

<TabItem label="Astro">

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

```astro
---
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>
```

</TabItem>

<TabItem label="SvelteKit">

Aquí tienes un ejemplo sencillo de cómo proteger una ruta en SvelteKit.

Crea un `+page.server.ts` en (o junto a) el directorio que quieras proteger:

```typescript
// File: src/routes/something/+page.server.ts

import { error } from '@sveltejs/kit'
import type { RequestEvent } from './$types'
import { getSession } from '@/lib/utils/auth'

export async function load(event: RequestEvent) {
  const session = getSession(event.request)
  if (!session) {
    // In case the user is not logged in
    // Send 403
    throw error(403, { message: 'Unauthorized' })
  }
  // If need to do something on the server side say fetch data for the user
  // This is the right block to do it
  return session
}
```

</TabItem>

</Tabs>

<div style="height: 1px; background: #C1C1C150; width: 100%;" />
