clerk-astro-patterns

Implement Clerk authentication patterns in Astro applications with middleware and SSR.

Updated Jun 20, 2026
One-click install
npx skills add https://github.com/sudarshan-krishnan/Sentinel_AIHackathon_Berkley_2026 --skill clerk-astro-patterns-sudarshan-krishnan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clerk-astro-patterns
Source: https://github.com/sudarshan-krishnan/Sentinel_AIHackathon_Berkley_2026/tree/main/app/.agents/skills/clerk-astro-patterns
Command: npx skills add https://github.com/sudarshan-krishnan/Sentinel_AIHackathon_Berkley_2026 --skill clerk-astro-patterns-sudarshan-krishnan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill removes the guesswork from adding Clerk authentication to Astro applications by showing the correct patterns for middleware, protected SSR pages, island components, and API routes.

Core Features & Use Cases

  • Route Protection: Protect dashboard, settings, and other authenticated routes with Clerk middleware and redirects for unauthenticated users.
  • SSR and API Auth: Read user and organization state from Astro.locals.auth() and context.locals.auth() to secure server-rendered pages and API endpoints.
  • Client-Side Islands: Build reactive header and navigation experiences with Clerk React components inside Astro islands using client hydration.
  • Use Case: Use this Skill when you need to combine static pages, SSR pages, and authenticated UI in one Astro app without breaking auth behavior.

Quick Start

Ask the Skill to protect your Astro dashboard routes, add SSR auth checks, and build a Clerk-powered header for signed-in and signed-out users.

Frequently Asked Questions about clerk-astro-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Clerk authentication middleware to protect Astro SSR routes?

To add Clerk authentication to Astro SSR routes, implement Clerk middleware to intercept route requests and redirect unauthenticated users. This secures server-rendered dashboard and settings pages by validating auth state before rendering.

How does Clerk auth context work in Astro API routes and server-rendered pages?

Clerk auth context in Astro API routes and SSR pages works by exposing user and organization state through context.locals.auth() and Astro.locals.auth(). You read this local auth state to secure server-side endpoints and page rendering.

Can I use Clerk React components inside hydrated Astro islands?

Yes, you can use Clerk React components inside Astro islands by applying client hydration. Using the client:load hydration directive ensures reactive header and navigation UI components render correctly for signed-in and signed-out users.

What is the best way to combine static pages, SSR pages, and authenticated UI in one Astro app?

The best way to combine static pages, SSR pages, and authenticated UI in one Astro app is using Clerk authentication patterns. This approach uses middleware, local auth context, and React islands to secure routes without breaking hybrid rendering workflows.

Why is my Clerk middleware not protecting matched Astro routes correctly?

Clerk middleware fails to protect matched Astro routes when route matching is misconfigured or @clerk/astro imports are incorrect. Ensure your middleware accurately matches protected paths and redirects unauthenticated users before they reach the page.