Skip to content

AUTH_SETUP

This Starlight site is now protected with GitHub OAuth authentication. Only whitelisted users can access any page.

  1. Go to GitHub Developer Settings
  2. Create a new OAuth App with these settings:
    • Application name: Your site name (e.g., “Notes Starlight”)
    • Homepage URL: https://yourdomain.com (or http://localhost:4321 for development)
    • Authorization callback URL: https://yourdomain.com/api/auth/callback/github (or http://localhost:4321/api/auth/callback/github for dev)
  1. Copy .env.example to .env:

    Terminal window
    cp .env.example .env
  2. Fill in your GitHub OAuth credentials in .env:

    GITHUB_CLIENT_ID=your_github_client_id
    GITHUB_CLIENT_SECRET=your_github_client_secret
    AUTH_SECRET=your_32_character_random_string
    AUTH_URL=https://yourdomain.com # or http://localhost:4321 for dev
  3. Generate a secure AUTH_SECRET:

    Terminal window
    openssl rand -base64 32

Edit auth.config.mjs and update the WHITELISTED_USERS array:

const WHITELISTED_USERS = [
"G-structure", // Replace with your GitHub username
"another-user", // Add more users as needed
"team-member",
];

Install the required authentication packages:

Terminal window
pnpm install @auth/core @auth/astro @auth/github auth-astro @astrojs/node

The site now runs in server mode and requires Node.js hosting:

Terminal window
# Development
pnpm run dev
# Production build
pnpm run build
# Preview production build
pnpm run preview
  • Complete Protection: All pages are protected by default
  • GitHub OAuth: Users must authenticate with their GitHub account
  • Whitelist System: Only GitHub usernames in the whitelist can access the site
  • Session Management: Users stay logged in with secure sessions
  • Auto-redirect: Unauthenticated users are redirected to the sign-in page
  1. User visits any page
  2. If not authenticated → redirect to /auth/signin
  3. User clicks “Sign in with GitHub”
  4. GitHub OAuth flow completes
  5. If username is whitelisted → access granted
  6. If username not whitelisted → error page shown
  • /auth/signin - Sign in page
  • /auth/error - Authentication error page
  • /api/auth/[...auth] - Authentication API endpoints
  • Server-side session validation
  • CSRF protection via Auth.js
  • Secure cookie settings
  • No client-side authentication bypass possible
  • Requires Node.js hosting (Vercel, Netlify Functions, VPS, etc.)
  • Cannot be deployed as static files
  • Environment variables must be set in production
  • Make sure to update AUTH_URL for your production domain