clerk
Clerk Integration Skill
This skill provides patterns for integrating Clerk's fully managed authentication service into a Go/React stack.
Architectural Standards
1. Go Backend Integration (Session & Hydration)
- Middleware: Use
clerk.WithSession()to inject the user's Clerk ID and metadata into the Go context. - Hydration: Implement a
SyncUserhelper that pulls the full user object from Clerk's API using theclerk-sdk-goand updates your local DB if needed. - Metadata: Use
privateMetadatafor sensitive backend-only fields (e.g., Stripe Customer ID) andpublicMetadatafor UI-facing attributes (e.g., User Role).
2. Reliable Webhooks (Svix)
- Verification: Always verify Clerk webhooks using the
svixpackage to prevent spoofing. - Idempotency: Webhooks can be delivered multiple times. Ensure your DB handlers are idempotent using a
webhook_idtable or check-before-update logic. - Events: Prioritize handling
user.created,user.updated, andsession.ended.
3. React Frontend Excellence
- Custom UI: While Clerk components are great, use
useClerk()anduseAuth()to build custom branded login flows for higher-tier enterprise feel. - TanStack Query:
const { getToken } = useAuth(); const { data } = useQuery({ queryKey: ['resource'], queryFn: async () => { const token = await getToken(); // Automatically handles refresh return fetchResource(token); } }); - Control Components: Use
<SignedIn>,<SignedOut>, and<Protect>for declarative access control.
4. Security Patterns
- SSO: Enable Enterprise SSO (SAML) in the Clerk dashboard. Map provider groups to internal roles.
- Rate Limiting: Implement rate limiting in the Go backend based on the Clerk
user_id.
Interaction Protocol
- Input: Clerk Publishable Key, Secret Key, and user synchronization requirements.
- Output: Go middleware/webhook handlers and React Clerk component integration.
Tag: Start your response with [CLERK-AUTH].
More from inselfcontroll/ai-agent-skills
rust_dioxus_framework
Acts as a Rust Dioxus Framework Specialist for building cross-platform UIs. Use when building desktop, web, or mobile apps using the Dioxus framework.
15testing_qa
Acts as a Testing and QA Agent. Use when writing unit, integration, or E2E tests, or when auditing code for test coverage.
2code-review
Expert for codebase-wide code reviews. Use when auditing Pull Requests, refactoring complex logic, or enforcing architectural and security standards across the ecosystem.
2principal_architect
Acts as a Principal Software Architect to design blueprints and enforce architectural rules. Use when designing system architecture, defining API contracts, or planning data flows.
2requirements_analyst
Acts as a Requirements Analyst to translate requests into specifications. Use when gathering user requirements, defining user stories, or creating technical specifications.
2workos
Expert for WorkOS integration, focusing on Enterprise SSO and Directory Sync. Use when implementing SSO, validating WorkOS JWTs in Go, or using WorkOS React components for enterprise auth.
1