--- import Layout from '../layouts/Layout.astro'; import { verifyAuth, requireAuth, authDebug } from '../lib/auth-unified'; export const prerender = false; // Test authentication let auth = null; let authError = null; let cookies = null; let headers = null; try { // Test unified auth - use Astro.cookies for pages auth = await verifyAuth(Astro.cookies); // Capture debug info cookies = Astro.request.headers.get('Cookie') || 'No cookies'; headers = { 'Authorization': Astro.request.headers.get('Authorization') || 'Not set', 'User-Agent': Astro.request.headers.get('User-Agent') || 'Not set', 'X-Forwarded-For': Astro.request.headers.get('X-Forwarded-For') || 'Not set' }; // Use debug utilities in development if (import.meta.env.DEV) { authDebug.logCookies(Astro.request); authDebug.logSession(auth?.session || null); } } catch (error) { authError = error instanceof Error ? error.message : 'Unknown error'; } ---

Unified Authentication System Test

Authentication Status

{auth ? (

✅ Authenticated

User ID: {auth.user.id}

Email: {auth.user.email}

Is Admin: {auth.isAdmin ? 'Yes' : 'No'}

Is Super Admin: {auth.isSuperAdmin ? 'Yes' : 'No'}

Organization ID: {auth.organizationId || 'None'}

Session Information

Token Type: {auth.session.token_type}

Expires At: {new Date((auth.session.expires_at || 0) * 1000).toLocaleString()}

Access Token: {auth.session.access_token.substring(0, 20)}...

User Dashboard {auth.isAdmin && ( Admin Dashboard )} {auth.isSuperAdmin && ( Super Dashboard )} Check Session API
) : (

❌ Not Authenticated

You are not logged in or your session has expired.

{authError && (

Error: {authError}

)}
)}

Request Debug Information

Cookies

{cookies}

Relevant Headers

{JSON.stringify(headers, null, 2)}

Unified Auth System Information

Features

  • ✅ Single source of truth for authentication
  • ✅ Works with both Request objects and AstroCookies
  • ✅ Supabase SSR integration
  • ✅ Bearer token fallback support
  • ✅ Role-based access control (User/Admin/Super Admin)
  • ✅ Organization-based access control
  • ✅ Security logging and rate limiting
  • ✅ Type-safe auth context

Usage

// In Astro pages
import { verifyAuth, requireAuth } from '../lib/auth-unified';

// Check auth (returns null if not authenticated)
const auth = await verifyAuth(Astro.request);

// Require auth (throws if not authenticated)
const auth = await requireAuth(Astro.request);

// Require admin
const auth = await requireAdmin(Astro.request);