What problem does it solve?
This Skill solves the common confusion of securing Astro apps with Clerk when pages can be SSR, static prerendered, or client-hydrated islands.
Core Features & Use Cases
- Middleware protection: Use
clerkMiddleware and createRouteMatcher to guard SSR routes like dashboards and settings.
- SSR auth inside pages: Read authenticated context via
Astro.locals.auth() and redirect unauthenticated users.
- Client-only islands: Use React Clerk hooks (e.g.,
useAuth, useUser) in client:load islands so auth works for static/prerendered pages.
- Authenticated API routes: Validate access inside API routes using
context.locals.auth() and return correct HTTP status codes.
- Org-aware rendering: Handle both missing user sessions and missing active organization with redirects.
Quick Start
Tell your AI to “Set up Clerk for an Astro app by configuring src/middleware.ts, protecting the /dashboard and /settings routes, authenticating SSR pages with Astro.locals.auth(), and ensuring static pages use a Clerk React island hydrated with client:load.”