LaunchFast Logo LaunchFast

Introducing Protected Pages comes with baked-in protected page(s) to help you prevent un-authenticated access to such pages. With the authentication methods such as Twitter OAuth 2.0, Google OAuth 2.0 and Credentials (email and password) built in with, such authenticated methods can be used by your users to get access to the protected pages in your application.

Here’s how easily you can create protected pages with

  • Create a file, say protected.astro with the following code:
// File: src/pages/protected.astro

import { getSession } from '@/lib/utils/auth'

const session = getSession(Astro.cookies)

if (!session) return webResponse('Unauthorized', 403, {})

<html lang="en">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
  <body class="font-display">
    <div class="relative mx-auto flex max-w-7xl flex-col px-8 py-8">
      <h1 class="pb-6 text-3xl font-medium text-launchfast">Protected Content!</h1>
  • That’s it! The getSession in the boilerplate takes care of decoding the session cookies and validating the user authentication status. If unauthorized, a 403 response is sent enforcing authentication based access to the content.

Worry not, with you get such a page protected.astro built for you with goodies on top.

Learn More Using Firebase Realtime Database in Astro with Vue: A Step-by-Step Guide → Authenticating users in Astro with Clerk and React: A Step-by-Step Guide → Deploy Astro to AWS Elasic Beanstalk: A Step-by-Step Guide →