clerk-auth
Clerk authentication patterns for React SPA with Supabase integration. Use when implementing authentication flows, protecting routes, managing user sessions, or bridging Clerk JWT to Supabase RLS. Triggers on auth, Clerk, login, signup, JWT, session, or protected route keywords.
- License 许可
- MIT
- 最近更新
- 2026-05-18
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- clerk-auth
- description
- Clerk authentication patterns for React SPA with Supabase integration. Use when implementing authentication flows, protecting routes, managing user sessions, or bridging Clerk JWT to Supabase RLS. Triggers on auth, Clerk, login, signup, JWT, session, or protected route keywords.
03 SKILL.md 正文
Clerk Authentication for Aurion Studio
Auth Architecture
Clerk (frontend) → JWT → TOOL_AUTH_SECRET → Bridge postMessage → Supabase RLS
Frontend Integration
<ClerkProvider>wraps entire app<SignedIn>/<SignedOut>for conditional renderinguseUser()for current user datauseAuth()for auth state andgetToken()useClerk()for programmatic sign in/out
Protected Routes
<Route element={<RequireAuth />}>
<Route path="/dashboard" element={<Dashboard />} />
</Route>
API Authentication
- Frontend gets JWT:
const token = await getToken() - Include in requests:
Authorization: Bearer ${token} - API verifies:
requireAuth()inapi/_lib/middleware.ts - Extract user ID from JWT claims
Tool Authentication Bridge
- Tools are on separate domains (cross-origin)
- Bridge:
postMessage+TOOL_AUTH_SECRET - Tool page → requests tool token → receives JWT for tool domain
- Endpoint:
POST /api/tool-token - CSRF token REQUIRED on this POST!
Supabase RLS Integration
- Clerk JWT includes
sub(user ID) - RLS policies use
auth.uid()matching Clerk user ID - Service role key bypasses RLS (backend only)
- Never expose service role key to client
Common Patterns
// Get user with credits info
const { user } = useUser()
const userId = user?.id
// Authenticated fetch
const authFetch = async (url: string, options?: RequestInit) => {
const token = await getToken()
return fetch(url, {
...options,
headers: {
...options?.headers,
'Authorization': `Bearer ${token}`,
'X-CSRF-Token': getCsrfToken(),
},
})
}
Error Handling
- 401: Token expired or invalid → redirect to sign in
- 403: CSRF token missing/invalid → include X-CSRF-Token header
- User not found: Clerk webhook creates user in Supabase on signup
04 同仓库更多 Skills
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
vercel-react-view-transitions
Guide for implementing smooth, native-feeling animations using React's View Transition API (`<ViewTransition>` component, `addTransitionType`, and CSS view transition pseudo-elements). Use this skill whenever the user wants to add page transitions, animate route changes, create shared element animations, animate enter/exit of components, animate list reorder, implement directional (forward/back) navigation animations, or integrate view transitions in Next.js. Also use when the user mentions view transitions, `startViewTransition`, `ViewTransition`, transition types, or asks about animating between UI states in React without third-party animation libraries.
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
vercel-composition-patterns
React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.
vercel-cli-with-tokens
Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".