plugins/clerk-auth-master/skills/clerk-frontend-sdks/SKILL.md
Use for Clerk frontend auth flows. PROACTIVELY activate for React, JavaScript, Vue, Nuxt, Astro, Expo, React Router, TanStack React Start, or SPA setup; ClerkProvider and publishable-key wiring; SignIn/SignUp/UserButton/UserProfile/OrganizationSwitcher; custom useUser/useAuth/useClerk/useSignIn/useSignUp/useSession/useOrganization flows; multi-session UX; cross-origin getToken() fetches; loading states, redirects, routing, CORS/cookies, or hydration bugs. Provides SDK selection, UI patterns, token-fetch templates, and frontend gotchas.
npx skillsauth add JosiahSiegel/claude-plugin-marketplace clerk-frontend-sdksInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill for client-side Clerk integration across React and other frontend frameworks. The main job is choosing the correct framework SDK, wiring provider context, selecting prebuilt UI vs custom flows, handling environment-specific redirects, and avoiding the mistake of treating client auth state as server authorization.
Prefer the dedicated framework SDK when one exists:
| App type | Preferred package/pattern |
|---|---|
| Next.js | @clerk/nextjs |
| React app without a stronger integration | @clerk/react |
| React Router framework | Clerk React Router SDK/patterns |
| TanStack React Start | Clerk TanStack integration |
| Astro | Clerk Astro integration |
| Nuxt/Vue | Clerk Nuxt/Vue integration |
| Expo/mobile | Clerk Expo/mobile integration |
| Plain JavaScript/non-React | ClerkJS |
Selecting the wrong SDK causes routing, SSR, hydration, and token propagation bugs. Check the package already installed before adding another package.
Wire the frontend provider near the root of the app. The provider should receive a publishable key or use the framework SDK's environment-variable convention. Never pass a secret key, webhook signing secret, or Backend API credential to browser code.
Use development and production Clerk instances deliberately. Auth bugs often come from mixing a development publishable key with production domains, production redirect URLs, production Backend API secrets, or production webhooks.
Provider-level options and environment variables must align with Clerk Dashboard URLs:
Prefer Clerk prebuilt components for standard auth UX:
Use custom flows when the product requires bespoke screens, progressive onboarding, embedded verification, or custom routing. For custom flows, use the specific sign-in/sign-up hooks and handle intermediate states explicitly. Do not assume a single submit call completes every flow; verification steps, MFA, passkeys, SSO, email codes, phone codes, OAuth, and pending session tasks can add state transitions.
Use hooks by purpose:
| Need | Hook |
|---|---|
| Current user object and loading state | useUser() |
| Auth status, user ID, session ID, token retrieval | useAuth() |
| Open modals, sign out, client methods | useClerk() |
| Custom sign-in flow | useSignIn() |
| Custom sign-up flow | useSignUp() |
| Active session details | useSession() |
| Multiple sessions | useSessionList() |
| Active organization | useOrganization() |
| Organization list/switching/creation | useOrganizationList() |
Always handle loading and unavailable states. Many frontend bugs are null-reference bugs caused by reading user, session, or organization before Clerk finishes loading.
Same-origin requests in supported framework integrations can often rely on Clerk-managed cookies. Cross-origin requests require a session token sent as a Bearer token.
Use this pattern in client code:
const { getToken } = useAuth()
const token = await getToken()
const res = await fetch('https://api.example.com/resource', {
headers: {
Authorization: `Bearer ${token}`,
},
})
if (!res.ok) {
throw new Error(`Request failed: ${res.status}`)
}
Plain JavaScript with ClerkJS uses the active session, conceptually:
const token = await Clerk.session.getToken()
Keep the gotchas attached to the code:
getToken() returns a Promise; always await it.fetch() does not throw for non-2xx responses; check res.ok.Authorization header.For same-origin app/API routes, Clerk-managed cookies usually provide the session token automatically. For a separate API origin, browsers do not automatically send a useful Clerk session to that API unless the architecture and cookie settings explicitly support it. Prefer Bearer-token authorization for cross-origin APIs.
When cross-origin requests fail:
Origin and Authorization.Access-Control-Allow-Origin for the exact frontend origin, not * when credentials are used.Access-Control-Allow-Headers includes Authorization and Content-Type.Authorization.Configure sign-in and sign-up URLs consistently across the SDK, environment variables, routes, and Clerk Dashboard. When implementing protected client-side routes, use client checks for UX only; enforce access on the server/API too.
For SPAs, guard route rendering with loading-aware logic:
Avoid flashes where protected content renders before auth status is known. For SSR frameworks, prefer server-side or middleware protection where available.
When organization features are enabled, design for active organization selection. UI may have a signed-in user but no active organization. Organization switching can change authorization for the same route, so fetch organization-scoped data after the active organization is known and cancel/refetch stale requests on org changes.
For applications that allow multiple sessions, use session-list APIs deliberately. Make active-session switching visible and test sign-out behavior for one session vs all sessions.
For custom flows:
Treat frontend Clerk state as presentation state. Any operation that reads private data, mutates data, changes billing, changes roles, changes organization membership, or performs admin work needs server-side authorization.
Do not embed sensitive authorization logic solely in hidden buttons, disabled UI, or client route guards. Users can call APIs directly.
Do not expose:
CLERK_SECRET_KEY or equivalent Backend API secret.clerkClient operations.Use environment-specific publishable keys and redirect URLs. Preview deployments often have different hostnames; verify they are allowed by the correct Clerk instance and do not accidentally use production secrets. For OAuth in production, configure provider-owned credentials rather than relying on development/shared Clerk credentials.
Authorization: Bearer <token>.Authorization header.development
Use for Clerk sessions, tokens, webhooks, orgs, and security. PROACTIVELY activate for session tokens, JWT templates, getToken(), custom claims, pending sessions, multi-session UX, organizations, roles, permissions, system vs custom permissions, features/plans, MFA/passkeys/password policy/bot protection, Clerk webhooks, Svix signatures, verifyWebhook(), user/org sync, retries/replays, environment variables, custom domains, secret rotation, logs, and auth security reviews. Provides token semantics, webhook idempotency, authorization defaults, and hardening checklist.
tools
Use for Clerk in Next.js. PROACTIVELY activate for @clerk/nextjs setup, App Router auth()/currentUser(), clerkMiddleware(), proxy.ts/middleware.ts, createRouteMatcher(), protected pages/layouts/Route Handlers/Server Actions/API routes/tRPC, auth.protect() role/permission/token checks, ClerkProvider placement, server-only clerkClient, Link prefetch, redirects, 401/404 auth failures, custom domains, __clerk proxy paths, and deployment gotchas. Provides file patterns, server/client boundary rules, matcher templates, and production checks.
development
Use for Clerk dev/prod readiness, deployment, and multi-language implementation planning. PROACTIVELY activate for environment variables, pk_test/sk_test vs pk_live/sk_live, local dev, preview/staging/prod instances, domains/DNS, redirects, OAuth credentials, custom domains/proxy, authorizedParties, CSP, CORS/cookies, webhooks/tunnels, Vercel/Netlify/Cloudflare/API gateways, monitoring/troubleshooting, and backends in Node/Express/Fastify, Python/FastAPI/Django/Flask, Go, Ruby/Rails, Java/Spring, .NET, PHP/Laravel. Provides checklists, rollout plans, and language-portable patterns.
development
Use for Clerk JWT and session token clock-skew issues. PROACTIVELY activate for "token-not-active-yet", "JWT cannot be used prior to not before", token-expired, nbf/iat/exp claim failures, clockSkewInMs in verifyToken/authenticateRequest, local dev container/WSL2/Docker Desktop time drift, NTP misconfiguration, paused VM clock, serverless cold-start clock issues, custom JWT template verification leeway across Node/Python/Go/Ruby/Java/.NET/PHP, debugging iat vs server-time delta, and separating real expiry from clock skew. Provides nbf/iat/exp semantics, Clerk and library clock-tolerance defaults, container time fix recipes, multi-language leeway patterns, diagnostics, and gotchas.