clerk
Installation
SKILL.md
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.