What problem does it solve?
Many Astro apps need consistent, server-aware authentication across SSR pages, API routes, and client-side islands, but Astro's dual rendering modes and hydration model make it easy to misconfigure auth and expose protected content or break client components.
Core Features & Use Cases
- Middleware routing: Examples for adding clerkMiddleware, using createRouteMatcher, and redirecting unauthenticated users to sign-in.
- SSR page protection: Guidance for using Astro.locals.auth() to gate server-rendered pages and fetch user-specific data.
- Island component auth: Patterns for using Clerk hooks in React islands with client:* directives to maintain reactive auth state.
- API route authorization: How to check context.locals.auth() in API handlers and use clerkClient for server-side user/organization data.
- Common pitfalls & fixes: Advice on prerendering, output mode, client hydration, and permission checks.
Quick Start
Add clerkMiddleware with createRouteMatcher in src/middleware.ts to guard /dashboard and /settings and redirect unauthenticated users to /sign-in.