Skip to content

Private Page(s)

Once user is authenticated, you can build private routes like a user dashboard, account, etc.

Here’s an example of a simple user dashboard showing private user data in the page:

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('/')

  <head> </head>
    The user that's logged name is {}