cfsa-antigravity 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +324 -0
- package/package.json +34 -0
- package/template/.agent/instructions/commands.md +48 -0
- package/template/.agent/instructions/patterns.md +61 -0
- package/template/.agent/instructions/structure.md +29 -0
- package/template/.agent/instructions/tech-stack.md +43 -0
- package/template/.agent/instructions/workflow.md +41 -0
- package/template/.agent/kit-sync.md +15 -0
- package/template/.agent/rules/boundary-not-placeholder.md +146 -0
- package/template/.agent/rules/completion-checklist.md +48 -0
- package/template/.agent/rules/decision-classification.md +103 -0
- package/template/.agent/rules/extensibility.md +47 -0
- package/template/.agent/rules/question-vs-command.md +81 -0
- package/template/.agent/rules/security-first.md +43 -0
- package/template/.agent/rules/specificity-standards.md +54 -0
- package/template/.agent/rules/tdd-contract-first.md +57 -0
- package/template/.agent/rules/vertical-slices.md +42 -0
- package/template/.agent/skill-library/MANIFEST.md +480 -0
- package/template/.agent/skill-library/README.md +38 -0
- package/template/.agent/skill-library/meta/brand-guidelines/SKILL.md +73 -0
- package/template/.agent/skill-library/meta/claude-code/README.md +9 -0
- package/template/.agent/skill-library/meta/claude-code/agent-development/SKILL.md +415 -0
- package/template/.agent/skill-library/meta/claude-code/hook-development/SKILL.md +712 -0
- package/template/.agent/skill-library/meta/claude-code/plugin-structure/SKILL.md +476 -0
- package/template/.agent/skill-library/meta/git-advanced/SKILL.md +972 -0
- package/template/.agent/skill-library/meta/mcp-builder/SKILL.md +236 -0
- package/template/.agent/skill-library/meta/product-marketing-context/SKILL.md +241 -0
- package/template/.agent/skill-library/meta/regex-patterns/SKILL.md +751 -0
- package/template/.agent/skill-library/meta/tmux-processes/SKILL.md +210 -0
- package/template/.agent/skill-library/meta/using-tmux-for-interactive-commands/SKILL.md +178 -0
- package/template/.agent/skill-library/stack/3d/threejs-pro/SKILL.md +300 -0
- package/template/.agent/skill-library/stack/ai/ai-sdk/SKILL.md +77 -0
- package/template/.agent/skill-library/stack/ai/langchain/SKILL.md +530 -0
- package/template/.agent/skill-library/stack/ai/ollama/SKILL.md +321 -0
- package/template/.agent/skill-library/stack/ai/openai-sdk/SKILL.md +549 -0
- package/template/.agent/skill-library/stack/analytics/google-analytics/SKILL.md +153 -0
- package/template/.agent/skill-library/stack/api/graphql/SKILL.md +1061 -0
- package/template/.agent/skill-library/stack/api/trpc/SKILL.md +576 -0
- package/template/.agent/skill-library/stack/auth/authjs/SKILL.md +569 -0
- package/template/.agent/skill-library/stack/auth/clerk/SKILL.md +590 -0
- package/template/.agent/skill-library/stack/auth/firebase-auth/SKILL.md +734 -0
- package/template/.agent/skill-library/stack/cms/payload-cms/SKILL.md +573 -0
- package/template/.agent/skill-library/stack/cms/shopify/SKILL.md +1193 -0
- package/template/.agent/skill-library/stack/cms/wordpress/SKILL.md +1104 -0
- package/template/.agent/skill-library/stack/css/sass-scss/SKILL.md +1121 -0
- package/template/.agent/skill-library/stack/css/tailwind-css-patterns/SKILL.md +863 -0
- package/template/.agent/skill-library/stack/css/tailwind-design-system/SKILL.md +490 -0
- package/template/.agent/skill-library/stack/css/vanilla-css/SKILL.md +1078 -0
- package/template/.agent/skill-library/stack/databases/clickhouse/SKILL.md +311 -0
- package/template/.agent/skill-library/stack/databases/influxdb/SKILL.md +280 -0
- package/template/.agent/skill-library/stack/databases/lancedb/SKILL.md +415 -0
- package/template/.agent/skill-library/stack/databases/mongodb/SKILL.md +1169 -0
- package/template/.agent/skill-library/stack/databases/neo4j/SKILL.md +839 -0
- package/template/.agent/skill-library/stack/databases/pgvector/SKILL.md +241 -0
- package/template/.agent/skill-library/stack/databases/pinecone/SKILL.md +212 -0
- package/template/.agent/skill-library/stack/databases/postgresql/SKILL.md +658 -0
- package/template/.agent/skill-library/stack/databases/qdrant/SKILL.md +312 -0
- package/template/.agent/skill-library/stack/databases/redis/SKILL.md +1079 -0
- package/template/.agent/skill-library/stack/databases/spacetimedb/SKILL.md +532 -0
- package/template/.agent/skill-library/stack/databases/sqlite/SKILL.md +1132 -0
- package/template/.agent/skill-library/stack/databases/supabase/SKILL.md +640 -0
- package/template/.agent/skill-library/stack/databases/surrealdb-expert/SKILL.md +945 -0
- package/template/.agent/skill-library/stack/databases/timescaledb/SKILL.md +745 -0
- package/template/.agent/skill-library/stack/databases/weaviate/SKILL.md +218 -0
- package/template/.agent/skill-library/stack/devops/github-actions/SKILL.md +554 -0
- package/template/.agent/skill-library/stack/devops/kubernetes/SKILL.md +950 -0
- package/template/.agent/skill-library/stack/devops/nginx/SKILL.md +841 -0
- package/template/.agent/skill-library/stack/devops/terraform/SKILL.md +860 -0
- package/template/.agent/skill-library/stack/email/resend/SKILL.md +391 -0
- package/template/.agent/skill-library/stack/engines/godot/SKILL.md +488 -0
- package/template/.agent/skill-library/stack/extensions/chrome-extension/SKILL.md +375 -0
- package/template/.agent/skill-library/stack/extensions/vscode-extension/SKILL.md +453 -0
- package/template/.agent/skill-library/stack/frameworks/astro-framework/SKILL.md +162 -0
- package/template/.agent/skill-library/stack/frameworks/electron/SKILL.md +1286 -0
- package/template/.agent/skill-library/stack/frameworks/fastapi/SKILL.md +650 -0
- package/template/.agent/skill-library/stack/frameworks/hono/SKILL.md +90 -0
- package/template/.agent/skill-library/stack/frameworks/nestjs/SKILL.md +878 -0
- package/template/.agent/skill-library/stack/frameworks/nextjs/SKILL.md +635 -0
- package/template/.agent/skill-library/stack/frameworks/nuxt/SKILL.md +564 -0
- package/template/.agent/skill-library/stack/frameworks/sveltekit/SKILL.md +614 -0
- package/template/.agent/skill-library/stack/frameworks/tauri/SKILL.md +920 -0
- package/template/.agent/skill-library/stack/gamedev/godot/SKILL.md +1032 -0
- package/template/.agent/skill-library/stack/gamedev/unity/SKILL.md +1175 -0
- package/template/.agent/skill-library/stack/hosting/aws/SKILL.md +467 -0
- package/template/.agent/skill-library/stack/hosting/cloudflare/SKILL.md +201 -0
- package/template/.agent/skill-library/stack/hosting/docker-expert/SKILL.md +409 -0
- package/template/.agent/skill-library/stack/hosting/vercel/SKILL.md +484 -0
- package/template/.agent/skill-library/stack/languages/bash-scripting/SKILL.md +773 -0
- package/template/.agent/skill-library/stack/languages/c-cpp/SKILL.md +712 -0
- package/template/.agent/skill-library/stack/languages/gdscript/SKILL.md +789 -0
- package/template/.agent/skill-library/stack/languages/go/SKILL.md +664 -0
- package/template/.agent/skill-library/stack/languages/java/SKILL.md +778 -0
- package/template/.agent/skill-library/stack/languages/kotlin/SKILL.md +665 -0
- package/template/.agent/skill-library/stack/languages/python/SKILL.md +678 -0
- package/template/.agent/skill-library/stack/languages/rust/SKILL.md +673 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/SKILL.md +141 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/advanced-generics.md +90 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/branded-types.md +57 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/builder-pattern.md +71 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/common-pitfalls.md +135 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/conditional-types.md +27 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/decorators.md +98 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/discriminated-unions.md +62 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/mapped-types.md +53 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/performance-best-practices.md +104 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/template-literal-types.md +49 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/testing-types.md +112 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/type-guards.md +70 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/type-inference.md +101 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/utility-types.md +98 -0
- package/template/.agent/skill-library/stack/languages/vanilla-javascript/SKILL.md +803 -0
- package/template/.agent/skill-library/stack/messaging/kafka/SKILL.md +235 -0
- package/template/.agent/skill-library/stack/mobile/expo-react-native/SKILL.md +665 -0
- package/template/.agent/skill-library/stack/mobile/flutter/SKILL.md +316 -0
- package/template/.agent/skill-library/stack/mobile/react-native/SKILL.md +337 -0
- package/template/.agent/skill-library/stack/monitoring/posthog/SKILL.md +396 -0
- package/template/.agent/skill-library/stack/monitoring/sentry/SKILL.md +509 -0
- package/template/.agent/skill-library/stack/observability/datadog/SKILL.md +179 -0
- package/template/.agent/skill-library/stack/observability/distributed-tracing/SKILL.md +140 -0
- package/template/.agent/skill-library/stack/observability/logging-best-practices/SKILL.md +168 -0
- package/template/.agent/skill-library/stack/observability/opentelemetry/SKILL.md +164 -0
- package/template/.agent/skill-library/stack/observability/prometheus-grafana/SKILL.md +246 -0
- package/template/.agent/skill-library/stack/observability/python-observability/SKILL.md +158 -0
- package/template/.agent/skill-library/stack/orm/drizzle-orm/SKILL.md +613 -0
- package/template/.agent/skill-library/stack/orm/prisma/SKILL.md +744 -0
- package/template/.agent/skill-library/stack/payments/lemonsqueezy/SKILL.md +393 -0
- package/template/.agent/skill-library/stack/payments/stripe-integration/SKILL.md +457 -0
- package/template/.agent/skill-library/stack/queue/bullmq/SKILL.md +385 -0
- package/template/.agent/skill-library/stack/queue/inngest/SKILL.md +438 -0
- package/template/.agent/skill-library/stack/realtime/socketio/SKILL.md +595 -0
- package/template/.agent/skill-library/stack/search/elasticsearch/SKILL.md +248 -0
- package/template/.agent/skill-library/stack/search/meilisearch/SKILL.md +385 -0
- package/template/.agent/skill-library/stack/security/crypto-patterns/SKILL.md +437 -0
- package/template/.agent/skill-library/stack/security/csp-cors-headers/SKILL.md +588 -0
- package/template/.agent/skill-library/stack/security/dependency-auditing/SKILL.md +560 -0
- package/template/.agent/skill-library/stack/security/input-sanitization/SKILL.md +430 -0
- package/template/.agent/skill-library/stack/security/owasp-web-security/SKILL.md +421 -0
- package/template/.agent/skill-library/stack/state/tanstack-query/SKILL.md +637 -0
- package/template/.agent/skill-library/stack/state/zustand/SKILL.md +483 -0
- package/template/.agent/skill-library/stack/storage/aws-s3/SKILL.md +415 -0
- package/template/.agent/skill-library/stack/testing/playwright/SKILL.md +641 -0
- package/template/.agent/skill-library/stack/testing/storybook/SKILL.md +923 -0
- package/template/.agent/skill-library/stack/testing/testing-library/SKILL.md +872 -0
- package/template/.agent/skill-library/stack/testing/vitest/SKILL.md +714 -0
- package/template/.agent/skill-library/stack/ui/react-best-practices/SKILL.md +877 -0
- package/template/.agent/skill-library/stack/ui/react-composition-patterns/SKILL.md +1107 -0
- package/template/.agent/skill-library/stack/ui/react-flow/SKILL.md +425 -0
- package/template/.agent/skill-library/stack/ui/shadcn-ui/SKILL.md +703 -0
- package/template/.agent/skill-library/surface/api/api-caching/SKILL.md +458 -0
- package/template/.agent/skill-library/surface/api/api-documentation-openapi/SKILL.md +697 -0
- package/template/.agent/skill-library/surface/api/api-error-handling/SKILL.md +478 -0
- package/template/.agent/skill-library/surface/api/api-security-checklist/SKILL.md +147 -0
- package/template/.agent/skill-library/surface/api/api-versioning/SKILL.md +420 -0
- package/template/.agent/skill-library/surface/api/email-best-practices/SKILL.md +59 -0
- package/template/.agent/skill-library/surface/api/rate-limiting-abuse-protection/SKILL.md +147 -0
- package/template/.agent/skill-library/surface/api/rest-api-design/SKILL.md +478 -0
- package/template/.agent/skill-library/surface/api/webhook-design/SKILL.md +752 -0
- package/template/.agent/skill-library/surface/cli/cli-configuration-management/SKILL.md +445 -0
- package/template/.agent/skill-library/surface/cli/cli-error-diagnostics/SKILL.md +515 -0
- package/template/.agent/skill-library/surface/cli/cli-shell-integration/SKILL.md +479 -0
- package/template/.agent/skill-library/surface/cli/cli-ux-design/SKILL.md +477 -0
- package/template/.agent/skill-library/surface/desktop/desktop-app-distribution/SKILL.md +416 -0
- package/template/.agent/skill-library/surface/desktop/desktop-security-sandboxing/SKILL.md +407 -0
- package/template/.agent/skill-library/surface/desktop/desktop-ux-conventions/SKILL.md +361 -0
- package/template/.agent/skill-library/surface/desktop/native-os-integration/SKILL.md +563 -0
- package/template/.agent/skill-library/surface/extension/browser-extension-patterns/SKILL.md +482 -0
- package/template/.agent/skill-library/surface/extension/plugin-architecture-design/SKILL.md +632 -0
- package/template/.agent/skill-library/surface/extension/vscode-extension-development/SKILL.md +728 -0
- package/template/.agent/skill-library/surface/mobile/app-store-submission/SKILL.md +304 -0
- package/template/.agent/skill-library/surface/mobile/mobile-offline-sync/SKILL.md +443 -0
- package/template/.agent/skill-library/surface/mobile/mobile-responsive-patterns/SKILL.md +432 -0
- package/template/.agent/skill-library/surface/mobile/push-notifications/SKILL.md +495 -0
- package/template/.agent/skill-library/surface/web/accessibility-compliance/SKILL.md +827 -0
- package/template/.agent/skill-library/surface/web/ai-seo/SKILL.md +398 -0
- package/template/.agent/skill-library/surface/web/ai-seo/references/content-patterns.md +285 -0
- package/template/.agent/skill-library/surface/web/ai-seo/references/platform-ranking-factors.md +152 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/SKILL.md +309 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/event-library.md +260 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/ga4-implementation.md +300 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/gtm-implementation.md +390 -0
- package/template/.agent/skill-library/surface/web/authentication-ui-flows/SKILL.md +530 -0
- package/template/.agent/skill-library/surface/web/dark-mode-theming/SKILL.md +516 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/SKILL.md +105 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/charts.csv +26 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/colors.csv +97 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/landing.csv +31 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/styles.csv +59 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/typography.csv +58 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/ux-guidelines.csv +100 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/core.py +258 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/design_system.py +1067 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/search.py +106 -0
- package/template/.agent/skill-library/surface/web/form-handling-validation/SKILL.md +675 -0
- package/template/.agent/skill-library/surface/web/frontend-design/SKILL.md +1393 -0
- package/template/.agent/skill-library/surface/web/frontend-design/templates/cppn-hero.tsx +299 -0
- package/template/.agent/skill-library/surface/web/frontend-design/templates/wave-hero.tsx +875 -0
- package/template/.agent/skill-library/surface/web/frontend-verification/SKILL.md +111 -0
- package/template/.agent/skill-library/surface/web/frontend-verification/scripts/ux_audit.py +739 -0
- package/template/.agent/skill-library/surface/web/i18n-localization/SKILL.md +154 -0
- package/template/.agent/skill-library/surface/web/offline-first-pwa/SKILL.md +657 -0
- package/template/.agent/skill-library/surface/web/page-cro/SKILL.md +182 -0
- package/template/.agent/skill-library/surface/web/page-cro/references/experiments.md +248 -0
- package/template/.agent/skill-library/surface/web/programmatic-seo/SKILL.md +238 -0
- package/template/.agent/skill-library/surface/web/programmatic-seo/references/playbooks.md +308 -0
- package/template/.agent/skill-library/surface/web/schema-markup/SKILL.md +179 -0
- package/template/.agent/skill-library/surface/web/schema-markup/references/schema-examples.md +398 -0
- package/template/.agent/skill-library/surface/web/seo-audit/SKILL.md +394 -0
- package/template/.agent/skill-library/surface/web/seo-audit/references/ai-writing-detection.md +200 -0
- package/template/.agent/skill-library/surface/web/web-performance-optimization/SKILL.md +646 -0
- package/template/.agent/skill-library/surface/web/web-scraping/SKILL.md +58 -0
- package/template/.agent/skills/accessibility/SKILL.md +522 -0
- package/template/.agent/skills/accessibility/references/WCAG.md +162 -0
- package/template/.agent/skills/adversarial-review/SKILL.md +90 -0
- package/template/.agent/skills/antigravity-workflows/SKILL.md +81 -0
- package/template/.agent/skills/antigravity-workflows/resources/implementation-playbook.md +36 -0
- package/template/.agent/skills/api-design-principles/SKILL.md +37 -0
- package/template/.agent/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/template/.agent/skills/api-design-principles/assets/rest-api-template.py +182 -0
- package/template/.agent/skills/api-design-principles/references/graphql-schema-design.md +583 -0
- package/template/.agent/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/template/.agent/skills/api-design-principles/resources/implementation-playbook.md +513 -0
- package/template/.agent/skills/api-versioning/SKILL.md +420 -0
- package/template/.agent/skills/architecture-mapping/SKILL.md +219 -0
- package/template/.agent/skills/bootstrap-agents/SKILL.md +259 -0
- package/template/.agent/skills/brainstorming/SKILL.md +236 -0
- package/template/.agent/skills/brand-guidelines/SKILL.md +44 -0
- package/template/.agent/skills/clean-code/SKILL.md +94 -0
- package/template/.agent/skills/code-review-pro/SKILL.md +152 -0
- package/template/.agent/skills/concise-planning/SKILL.md +68 -0
- package/template/.agent/skills/cross-layer-consistency/SKILL.md +117 -0
- package/template/.agent/skills/database-schema-design/SKILL.md +429 -0
- package/template/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/template/.agent/skills/design-anti-cliche/SKILL.md +159 -0
- package/template/.agent/skills/design-direction/SKILL.md +45 -0
- package/template/.agent/skills/error-handling-patterns/SKILL.md +721 -0
- package/template/.agent/skills/find-skills/SKILL.md +145 -0
- package/template/.agent/skills/git-advanced/SKILL.md +972 -0
- package/template/.agent/skills/git-workflow/SKILL.md +420 -0
- package/template/.agent/skills/idea-extraction/SKILL.md +271 -0
- package/template/.agent/skills/logging-best-practices/SKILL.md +851 -0
- package/template/.agent/skills/migration-management/SKILL.md +384 -0
- package/template/.agent/skills/minimalist-surgical-development/SKILL.md +69 -0
- package/template/.agent/skills/parallel-agents/SKILL.md +165 -0
- package/template/.agent/skills/parallel-debugging/SKILL.md +135 -0
- package/template/.agent/skills/parallel-feature-development/SKILL.md +166 -0
- package/template/.agent/skills/performance-budgeting/SKILL.md +144 -0
- package/template/.agent/skills/pipeline-rubrics/SKILL.md +51 -0
- package/template/.agent/skills/pipeline-rubrics/references/architecture-rubric.md +19 -0
- package/template/.agent/skills/pipeline-rubrics/references/be-rubric.md +21 -0
- package/template/.agent/skills/pipeline-rubrics/references/fe-rubric.md +20 -0
- package/template/.agent/skills/pipeline-rubrics/references/ia-rubric.md +19 -0
- package/template/.agent/skills/pipeline-rubrics/references/scoring.md +28 -0
- package/template/.agent/skills/pipeline-rubrics/references/vision-rubric.md +11 -0
- package/template/.agent/skills/prd-templates/SKILL.md +88 -0
- package/template/.agent/skills/prd-templates/references/architecture-design-template.md +88 -0
- package/template/.agent/skills/prd-templates/references/be-spec-template.md +101 -0
- package/template/.agent/skills/prd-templates/references/data-placement-template.md +74 -0
- package/template/.agent/skills/prd-templates/references/decomposition-templates.md +211 -0
- package/template/.agent/skills/prd-templates/references/design-system-decisions.md +198 -0
- package/template/.agent/skills/prd-templates/references/engineering-standards-template.md +124 -0
- package/template/.agent/skills/prd-templates/references/fe-classification-procedures.md +47 -0
- package/template/.agent/skills/prd-templates/references/fe-spec-template.md +84 -0
- package/template/.agent/skills/prd-templates/references/infrastructure-report-template.md +71 -0
- package/template/.agent/skills/prd-templates/references/operational-templates.md +116 -0
- package/template/.agent/skills/prd-templates/references/placeholder-guard-template.md +21 -0
- package/template/.agent/skills/prd-templates/references/surface-model.md +61 -0
- package/template/.agent/skills/prd-templates/references/vision-template.md +66 -0
- package/template/.agent/skills/prompt-engineer/README.md +659 -0
- package/template/.agent/skills/prompt-engineer/SKILL.md +249 -0
- package/template/.agent/skills/regex-patterns/SKILL.md +751 -0
- package/template/.agent/skills/resolve-ambiguity/SKILL.md +278 -0
- package/template/.agent/skills/rest-api-design/SKILL.md +478 -0
- package/template/.agent/skills/security-scanning-security-hardening/SKILL.md +231 -0
- package/template/.agent/skills/session-continuity/SKILL.md +730 -0
- package/template/.agent/skills/session-continuity/protocols/01-session-resumption.md +38 -0
- package/template/.agent/skills/session-continuity/protocols/02-progress-generation.md +85 -0
- package/template/.agent/skills/session-continuity/protocols/03-progress-update.md +70 -0
- package/template/.agent/skills/session-continuity/protocols/04-pattern-extraction.md +60 -0
- package/template/.agent/skills/session-continuity/protocols/05-session-close.md +37 -0
- package/template/.agent/skills/session-continuity/protocols/06-decision-analysis.md +84 -0
- package/template/.agent/skills/session-continuity/protocols/07-spec-pipeline-generation.md +48 -0
- package/template/.agent/skills/session-continuity/protocols/08-spec-pipeline-update.md +43 -0
- package/template/.agent/skills/session-continuity/protocols/09-parallel-claim.md +122 -0
- package/template/.agent/skills/session-continuity/protocols/10-placeholder-verification-gate.md +104 -0
- package/template/.agent/skills/session-continuity/protocols/ambiguity-gates.md +48 -0
- package/template/.agent/skills/skill-creator/LICENSE.txt +202 -0
- package/template/.agent/skills/skill-creator/README.md +270 -0
- package/template/.agent/skills/skill-creator/SKILL.md +590 -0
- package/template/.agent/skills/skill-creator/references/output-patterns.md +82 -0
- package/template/.agent/skills/skill-creator/references/workflows.md +28 -0
- package/template/.agent/skills/skill-creator/scripts/init_skill.py +303 -0
- package/template/.agent/skills/skill-creator/scripts/package_skill.py +110 -0
- package/template/.agent/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/template/.agent/skills/spec-writing/SKILL.md +110 -0
- package/template/.agent/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/template/.agent/skills/systematic-debugging/SKILL.md +297 -0
- package/template/.agent/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/template/.agent/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/template/.agent/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/template/.agent/skills/systematic-debugging/find-polluter.sh +63 -0
- package/template/.agent/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/template/.agent/skills/systematic-debugging/test-academic.md +14 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/template/.agent/skills/tdd-workflow/SKILL.md +409 -0
- package/template/.agent/skills/tech-stack-catalog/SKILL.md +49 -0
- package/template/.agent/skills/tech-stack-catalog/references/constraint-questions.md +21 -0
- package/template/.agent/skills/tech-stack-catalog/references/dev-tooling-decisions.md +37 -0
- package/template/.agent/skills/tech-stack-catalog/references/surface-decision-tables.md +69 -0
- package/template/.agent/skills/technical-writer/SKILL.md +242 -0
- package/template/.agent/skills/testing-strategist/SKILL.md +932 -0
- package/template/.agent/skills/verification-before-completion/SKILL.md +145 -0
- package/template/.agent/skills/workflow-automation/SKILL.md +73 -0
- package/template/.agent/workflows/audit-ambiguity-execute.md +165 -0
- package/template/.agent/workflows/audit-ambiguity-rubrics.md +83 -0
- package/template/.agent/workflows/audit-ambiguity.md +64 -0
- package/template/.agent/workflows/bootstrap-agents-fill.md +201 -0
- package/template/.agent/workflows/bootstrap-agents-provision.md +197 -0
- package/template/.agent/workflows/bootstrap-agents.md +66 -0
- package/template/.agent/workflows/create-prd-architecture.md +119 -0
- package/template/.agent/workflows/create-prd-compile.md +138 -0
- package/template/.agent/workflows/create-prd-design-system.md +135 -0
- package/template/.agent/workflows/create-prd-security.md +113 -0
- package/template/.agent/workflows/create-prd-stack.md +91 -0
- package/template/.agent/workflows/create-prd.md +168 -0
- package/template/.agent/workflows/decompose-architecture-structure.md +82 -0
- package/template/.agent/workflows/decompose-architecture-validate.md +119 -0
- package/template/.agent/workflows/decompose-architecture.md +111 -0
- package/template/.agent/workflows/evolve-contract.md +98 -0
- package/template/.agent/workflows/evolve-feature-cascade.md +140 -0
- package/template/.agent/workflows/evolve-feature-classify.md +116 -0
- package/template/.agent/workflows/evolve-feature.md +56 -0
- package/template/.agent/workflows/ideate-discover.md +144 -0
- package/template/.agent/workflows/ideate-extract.md +129 -0
- package/template/.agent/workflows/ideate-validate.md +117 -0
- package/template/.agent/workflows/ideate.md +113 -0
- package/template/.agent/workflows/implement-slice-setup.md +113 -0
- package/template/.agent/workflows/implement-slice-tdd.md +198 -0
- package/template/.agent/workflows/implement-slice.md +50 -0
- package/template/.agent/workflows/plan-phase.md +202 -0
- package/template/.agent/workflows/propagate-decision-apply.md +135 -0
- package/template/.agent/workflows/propagate-decision-scan.md +147 -0
- package/template/.agent/workflows/propagate-decision.md +56 -0
- package/template/.agent/workflows/remediate-pipeline-assess.md +138 -0
- package/template/.agent/workflows/remediate-pipeline-execute.md +135 -0
- package/template/.agent/workflows/remediate-pipeline.md +55 -0
- package/template/.agent/workflows/resolve-ambiguity.md +82 -0
- package/template/.agent/workflows/sync-kit.md +209 -0
- package/template/.agent/workflows/update-architecture-map.md +74 -0
- package/template/.agent/workflows/validate-phase.md +219 -0
- package/template/.agent/workflows/verify-infrastructure.md +207 -0
- package/template/.agent/workflows/write-architecture-spec-deepen.md +139 -0
- package/template/.agent/workflows/write-architecture-spec-design.md +202 -0
- package/template/.agent/workflows/write-architecture-spec.md +63 -0
- package/template/.agent/workflows/write-be-spec-classify.md +165 -0
- package/template/.agent/workflows/write-be-spec-write.md +98 -0
- package/template/.agent/workflows/write-be-spec.md +76 -0
- package/template/.agent/workflows/write-fe-spec-classify.md +170 -0
- package/template/.agent/workflows/write-fe-spec-write.md +94 -0
- package/template/.agent/workflows/write-fe-spec.md +71 -0
- package/template/AGENTS.md +176 -0
- package/template/GEMINI.md +177 -0
- package/template/docs/README.md +187 -0
- package/template/docs/audits/.gitkeep +0 -0
- package/template/docs/audits/README.md +10 -0
- package/template/docs/plans/.gitkeep +0 -0
- package/template/docs/plans/README.md +21 -0
- package/template/docs/plans/be/.gitkeep +0 -0
- package/template/docs/plans/be/README.md +11 -0
- package/template/docs/plans/fe/.gitkeep +0 -0
- package/template/docs/plans/fe/README.md +11 -0
- package/template/docs/plans/ia/.gitkeep +0 -0
- package/template/docs/plans/ia/README.md +17 -0
- package/template/docs/plans/ia/deep-dives/.gitkeep +0 -0
- package/template/docs/plans/ia/deep-dives/README.md +5 -0
- package/template/docs/plans/phases/.gitkeep +0 -0
- package/template/docs/plans/phases/README.md +11 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: clerk
|
|
3
|
+
description: Comprehensive Clerk authentication skill covering setup, sign-in/sign-up components, middleware (clerkMiddleware), server-side auth (currentUser, auth), client hooks (useUser, useAuth, useClerk), user management, organizations, RBAC, webhooks, custom flows, and integration with Next.js and Astro. Use when implementing authentication with Clerk.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Clerk Authentication
|
|
8
|
+
|
|
9
|
+
Drop-in authentication and user management platform with pre-built UI components, session management, RBAC, organizations, and webhooks.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
### Installation (Next.js)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @clerk/nextjs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Environment Variables
|
|
20
|
+
|
|
21
|
+
```env
|
|
22
|
+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
|
|
23
|
+
CLERK_SECRET_KEY=sk_test_...
|
|
24
|
+
|
|
25
|
+
# Optional: custom routes
|
|
26
|
+
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
|
|
27
|
+
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
|
|
28
|
+
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
|
|
29
|
+
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/onboarding
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Provider Setup (Next.js App Router)
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// app/layout.tsx
|
|
36
|
+
import { ClerkProvider } from '@clerk/nextjs';
|
|
37
|
+
|
|
38
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
39
|
+
return (
|
|
40
|
+
<ClerkProvider>
|
|
41
|
+
<html lang="en">
|
|
42
|
+
<body>{children}</body>
|
|
43
|
+
</html>
|
|
44
|
+
</ClerkProvider>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Astro Integration
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx astro add @clerk/astro
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// astro.config.mjs
|
|
57
|
+
import { defineConfig } from 'astro/config';
|
|
58
|
+
import clerk from '@clerk/astro';
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
integrations: [clerk()],
|
|
62
|
+
output: 'server',
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```astro
|
|
67
|
+
---
|
|
68
|
+
// src/pages/dashboard.astro
|
|
69
|
+
const { userId } = Astro.locals.auth();
|
|
70
|
+
if (!userId) {
|
|
71
|
+
return Astro.redirect('/sign-in');
|
|
72
|
+
}
|
|
73
|
+
---
|
|
74
|
+
<h1>Dashboard</h1>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Middleware
|
|
78
|
+
|
|
79
|
+
### Next.js Middleware
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// middleware.ts (project root)
|
|
83
|
+
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
|
|
84
|
+
|
|
85
|
+
const isPublicRoute = createRouteMatcher([
|
|
86
|
+
'/',
|
|
87
|
+
'/sign-in(.*)',
|
|
88
|
+
'/sign-up(.*)',
|
|
89
|
+
'/api/webhooks(.*)',
|
|
90
|
+
'/pricing',
|
|
91
|
+
'/about',
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const isAdminRoute = createRouteMatcher(['/admin(.*)']);
|
|
95
|
+
|
|
96
|
+
export default clerkMiddleware(async (auth, request) => {
|
|
97
|
+
// Protect non-public routes
|
|
98
|
+
if (!isPublicRoute(request)) {
|
|
99
|
+
await auth.protect();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Admin routes require admin role
|
|
103
|
+
if (isAdminRoute(request)) {
|
|
104
|
+
await auth.protect({ role: 'org:admin' });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export const config = {
|
|
109
|
+
matcher: [
|
|
110
|
+
// Skip Next.js internals and static files
|
|
111
|
+
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
|
|
112
|
+
'/(api|trpc)(.*)',
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Pre-Built Components
|
|
118
|
+
|
|
119
|
+
### Sign In / Sign Up Pages
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// app/sign-in/[[...sign-in]]/page.tsx
|
|
123
|
+
import { SignIn } from '@clerk/nextjs';
|
|
124
|
+
|
|
125
|
+
export default function SignInPage() {
|
|
126
|
+
return (
|
|
127
|
+
<div className="flex items-center justify-center min-h-screen">
|
|
128
|
+
<SignIn
|
|
129
|
+
appearance={{
|
|
130
|
+
elements: {
|
|
131
|
+
rootBox: 'mx-auto',
|
|
132
|
+
card: 'shadow-lg',
|
|
133
|
+
},
|
|
134
|
+
}}
|
|
135
|
+
/>
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// app/sign-up/[[...sign-up]]/page.tsx
|
|
141
|
+
import { SignUp } from '@clerk/nextjs';
|
|
142
|
+
|
|
143
|
+
export default function SignUpPage() {
|
|
144
|
+
return (
|
|
145
|
+
<div className="flex items-center justify-center min-h-screen">
|
|
146
|
+
<SignUp />
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### User Button and Profile
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { UserButton, UserProfile } from '@clerk/nextjs';
|
|
156
|
+
|
|
157
|
+
// Compact button with dropdown
|
|
158
|
+
function Header() {
|
|
159
|
+
return (
|
|
160
|
+
<nav>
|
|
161
|
+
<UserButton
|
|
162
|
+
afterSignOutUrl="/"
|
|
163
|
+
appearance={{
|
|
164
|
+
elements: {
|
|
165
|
+
avatarBox: 'h-10 w-10',
|
|
166
|
+
},
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
</nav>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Full profile management page
|
|
174
|
+
// app/user-profile/[[...user-profile]]/page.tsx
|
|
175
|
+
export default function UserProfilePage() {
|
|
176
|
+
return <UserProfile path="/user-profile" />;
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Organization Components
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import {
|
|
184
|
+
OrganizationSwitcher,
|
|
185
|
+
CreateOrganization,
|
|
186
|
+
OrganizationProfile,
|
|
187
|
+
OrganizationList,
|
|
188
|
+
} from '@clerk/nextjs';
|
|
189
|
+
|
|
190
|
+
function OrgSwitcher() {
|
|
191
|
+
return (
|
|
192
|
+
<OrganizationSwitcher
|
|
193
|
+
hidePersonal={false}
|
|
194
|
+
afterCreateOrganizationUrl="/org/:slug"
|
|
195
|
+
afterSelectOrganizationUrl="/org/:slug"
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Server-Side Auth
|
|
202
|
+
|
|
203
|
+
### Server Components (Next.js App Router)
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// app/dashboard/page.tsx
|
|
207
|
+
import { currentUser, auth } from '@clerk/nextjs/server';
|
|
208
|
+
|
|
209
|
+
export default async function DashboardPage() {
|
|
210
|
+
// Get full user object
|
|
211
|
+
const user = await currentUser();
|
|
212
|
+
if (!user) {
|
|
213
|
+
redirect('/sign-in');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Or get just the auth object
|
|
217
|
+
const { userId, orgId, orgRole } = await auth();
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<div>
|
|
221
|
+
<h1>Welcome, {user.firstName}</h1>
|
|
222
|
+
<p>User ID: {userId}</p>
|
|
223
|
+
{orgId && <p>Organization: {orgId} (Role: {orgRole})</p>}
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### API Routes
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
// app/api/profile/route.ts
|
|
233
|
+
import { auth, currentUser } from '@clerk/nextjs/server';
|
|
234
|
+
import { NextResponse } from 'next/server';
|
|
235
|
+
|
|
236
|
+
export async function GET() {
|
|
237
|
+
const { userId } = await auth();
|
|
238
|
+
if (!userId) {
|
|
239
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const user = await currentUser();
|
|
243
|
+
return NextResponse.json({
|
|
244
|
+
id: user?.id,
|
|
245
|
+
email: user?.emailAddresses[0]?.emailAddress,
|
|
246
|
+
name: `${user?.firstName} ${user?.lastName}`,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function PATCH(request: Request) {
|
|
251
|
+
const { userId } = await auth();
|
|
252
|
+
if (!userId) {
|
|
253
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const body = await request.json();
|
|
257
|
+
// Update user in your database using userId as the key
|
|
258
|
+
await db.user.update({ where: { clerkId: userId }, data: body });
|
|
259
|
+
|
|
260
|
+
return NextResponse.json({ success: true });
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Auth Protect with Permissions
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
import { auth } from '@clerk/nextjs/server';
|
|
268
|
+
|
|
269
|
+
export async function DELETE(request: Request) {
|
|
270
|
+
// Throws 403 if user doesn't have the permission
|
|
271
|
+
const { userId } = await auth.protect({
|
|
272
|
+
permission: 'org:posts:delete',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Or check role
|
|
276
|
+
const { userId: adminId } = await auth.protect({
|
|
277
|
+
role: 'org:admin',
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Client-Side Hooks
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
'use client';
|
|
286
|
+
|
|
287
|
+
import { useUser, useAuth, useClerk, useOrganization, useSignIn } from '@clerk/nextjs';
|
|
288
|
+
|
|
289
|
+
function UserDashboard() {
|
|
290
|
+
const { user, isLoaded, isSignedIn } = useUser();
|
|
291
|
+
const { userId, sessionId, getToken, signOut } = useAuth();
|
|
292
|
+
const { openUserProfile, openSignIn } = useClerk();
|
|
293
|
+
const { organization, membership } = useOrganization();
|
|
294
|
+
|
|
295
|
+
if (!isLoaded) return <div>Loading...</div>;
|
|
296
|
+
if (!isSignedIn) return <div>Not signed in</div>;
|
|
297
|
+
|
|
298
|
+
// Get token for external API calls
|
|
299
|
+
async function callExternalAPI() {
|
|
300
|
+
const token = await getToken({ template: 'supabase' }); // named JWT template
|
|
301
|
+
// or
|
|
302
|
+
const defaultToken = await getToken(); // default session token
|
|
303
|
+
|
|
304
|
+
const res = await fetch('/api/data', {
|
|
305
|
+
headers: { Authorization: `Bearer ${defaultToken}` },
|
|
306
|
+
});
|
|
307
|
+
return res.json();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<div>
|
|
312
|
+
<p>Hello, {user.firstName}</p>
|
|
313
|
+
<p>Email: {user.primaryEmailAddress?.emailAddress}</p>
|
|
314
|
+
<img src={user.imageUrl} alt="Avatar" />
|
|
315
|
+
<button onClick={() => openUserProfile()}>Edit Profile</button>
|
|
316
|
+
<button onClick={() => signOut()}>Sign Out</button>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Update User Metadata
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
'use client';
|
|
326
|
+
|
|
327
|
+
import { useUser } from '@clerk/nextjs';
|
|
328
|
+
|
|
329
|
+
function OnboardingForm() {
|
|
330
|
+
const { user } = useUser();
|
|
331
|
+
|
|
332
|
+
async function handleSubmit(formData: FormData) {
|
|
333
|
+
await user?.update({
|
|
334
|
+
firstName: formData.get('firstName') as string,
|
|
335
|
+
lastName: formData.get('lastName') as string,
|
|
336
|
+
unsafeMetadata: {
|
|
337
|
+
onboardingComplete: true,
|
|
338
|
+
preferences: {
|
|
339
|
+
theme: formData.get('theme'),
|
|
340
|
+
notifications: formData.get('notifications') === 'on',
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return <form onSubmit={handleSubmit}>...</form>;
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Webhooks
|
|
351
|
+
|
|
352
|
+
### Webhook Handler
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// app/api/webhooks/clerk/route.ts
|
|
356
|
+
import { Webhook } from 'svix';
|
|
357
|
+
import { headers } from 'next/headers';
|
|
358
|
+
import type { WebhookEvent } from '@clerk/nextjs/server';
|
|
359
|
+
|
|
360
|
+
export async function POST(request: Request) {
|
|
361
|
+
const WEBHOOK_SECRET = process.env.CLERK_WEBHOOK_SECRET;
|
|
362
|
+
if (!WEBHOOK_SECRET) {
|
|
363
|
+
throw new Error('Missing CLERK_WEBHOOK_SECRET');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const headerPayload = await headers();
|
|
367
|
+
const svixId = headerPayload.get('svix-id');
|
|
368
|
+
const svixTimestamp = headerPayload.get('svix-timestamp');
|
|
369
|
+
const svixSignature = headerPayload.get('svix-signature');
|
|
370
|
+
|
|
371
|
+
if (!svixId || !svixTimestamp || !svixSignature) {
|
|
372
|
+
return new Response('Missing svix headers', { status: 400 });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const payload = await request.json();
|
|
376
|
+
const body = JSON.stringify(payload);
|
|
377
|
+
|
|
378
|
+
const wh = new Webhook(WEBHOOK_SECRET);
|
|
379
|
+
let event: WebhookEvent;
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
event = wh.verify(body, {
|
|
383
|
+
'svix-id': svixId,
|
|
384
|
+
'svix-timestamp': svixTimestamp,
|
|
385
|
+
'svix-signature': svixSignature,
|
|
386
|
+
}) as WebhookEvent;
|
|
387
|
+
} catch {
|
|
388
|
+
return new Response('Invalid signature', { status: 400 });
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
switch (event.type) {
|
|
392
|
+
case 'user.created': {
|
|
393
|
+
const { id, email_addresses, first_name, last_name, image_url } = event.data;
|
|
394
|
+
await db.user.create({
|
|
395
|
+
data: {
|
|
396
|
+
clerkId: id,
|
|
397
|
+
email: email_addresses[0]?.email_address ?? '',
|
|
398
|
+
name: `${first_name ?? ''} ${last_name ?? ''}`.trim(),
|
|
399
|
+
avatarUrl: image_url,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case 'user.updated': {
|
|
405
|
+
const { id, first_name, last_name, image_url } = event.data;
|
|
406
|
+
await db.user.update({
|
|
407
|
+
where: { clerkId: id },
|
|
408
|
+
data: {
|
|
409
|
+
name: `${first_name ?? ''} ${last_name ?? ''}`.trim(),
|
|
410
|
+
avatarUrl: image_url,
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case 'user.deleted': {
|
|
416
|
+
if (event.data.id) {
|
|
417
|
+
await db.user.delete({ where: { clerkId: event.data.id } });
|
|
418
|
+
}
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
case 'organization.created': {
|
|
422
|
+
// Sync org to your database
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return new Response('OK', { status: 200 });
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Organizations and RBAC
|
|
432
|
+
|
|
433
|
+
### Define Roles and Permissions
|
|
434
|
+
|
|
435
|
+
In Clerk Dashboard > Organizations > Roles:
|
|
436
|
+
|
|
437
|
+
| Role | Key | Permissions |
|
|
438
|
+
|------|-----|-------------|
|
|
439
|
+
| Admin | `org:admin` | All permissions |
|
|
440
|
+
| Member | `org:member` | `org:posts:read`, `org:posts:create` |
|
|
441
|
+
| Viewer | `org:viewer` | `org:posts:read` |
|
|
442
|
+
|
|
443
|
+
### Check Permissions in Code
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
import { auth } from '@clerk/nextjs/server';
|
|
447
|
+
|
|
448
|
+
export async function GET() {
|
|
449
|
+
const { has } = await auth();
|
|
450
|
+
|
|
451
|
+
// Check specific permission
|
|
452
|
+
if (!has({ permission: 'org:posts:create' })) {
|
|
453
|
+
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Check role
|
|
457
|
+
if (!has({ role: 'org:admin' })) {
|
|
458
|
+
return NextResponse.json({ error: 'Admin only' }, { status: 403 });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
// Client-side
|
|
465
|
+
'use client';
|
|
466
|
+
import { useAuth } from '@clerk/nextjs';
|
|
467
|
+
import { Protect } from '@clerk/nextjs';
|
|
468
|
+
|
|
469
|
+
function AdminPanel() {
|
|
470
|
+
const { has } = useAuth();
|
|
471
|
+
|
|
472
|
+
// Imperative check
|
|
473
|
+
if (!has?.({ role: 'org:admin' })) {
|
|
474
|
+
return <p>Access denied</p>;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return <div>Admin content</div>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Declarative component
|
|
481
|
+
function ConditionalContent() {
|
|
482
|
+
return (
|
|
483
|
+
<Protect permission="org:posts:create" fallback={<p>You cannot create posts</p>}>
|
|
484
|
+
<CreatePostForm />
|
|
485
|
+
</Protect>
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
## Custom Sign-In Flow
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
'use client';
|
|
494
|
+
|
|
495
|
+
import { useSignIn } from '@clerk/nextjs';
|
|
496
|
+
import { useState } from 'react';
|
|
497
|
+
|
|
498
|
+
function CustomSignIn() {
|
|
499
|
+
const { signIn, setActive, isLoaded } = useSignIn();
|
|
500
|
+
const [email, setEmail] = useState('');
|
|
501
|
+
const [password, setPassword] = useState('');
|
|
502
|
+
const [error, setError] = useState('');
|
|
503
|
+
|
|
504
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
505
|
+
e.preventDefault();
|
|
506
|
+
if (!isLoaded) return;
|
|
507
|
+
|
|
508
|
+
try {
|
|
509
|
+
const result = await signIn.create({
|
|
510
|
+
identifier: email,
|
|
511
|
+
password,
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
if (result.status === 'complete') {
|
|
515
|
+
await setActive({ session: result.createdSessionId });
|
|
516
|
+
// Redirect to dashboard
|
|
517
|
+
} else {
|
|
518
|
+
// Handle MFA or other verification steps
|
|
519
|
+
console.log('Additional steps needed:', result.status);
|
|
520
|
+
}
|
|
521
|
+
} catch (err: any) {
|
|
522
|
+
setError(err.errors?.[0]?.message ?? 'Sign-in failed');
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return (
|
|
527
|
+
<form onSubmit={handleSubmit}>
|
|
528
|
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
529
|
+
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} />
|
|
530
|
+
{error && <p className="text-red-500">{error}</p>}
|
|
531
|
+
<button type="submit">Sign In</button>
|
|
532
|
+
</form>
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
## JWT Templates (External Auth)
|
|
538
|
+
|
|
539
|
+
Configure JWT templates in Clerk Dashboard for external services:
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
// Get a JWT for Supabase, Hasura, or any external service
|
|
543
|
+
const token = await getToken({ template: 'supabase' });
|
|
544
|
+
|
|
545
|
+
// Use with Supabase
|
|
546
|
+
import { createClient } from '@supabase/supabase-js';
|
|
547
|
+
|
|
548
|
+
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
|
|
549
|
+
global: {
|
|
550
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
## Appearance Customization
|
|
556
|
+
|
|
557
|
+
```typescript
|
|
558
|
+
<ClerkProvider
|
|
559
|
+
appearance={{
|
|
560
|
+
baseTheme: dark, // import { dark } from '@clerk/themes'
|
|
561
|
+
variables: {
|
|
562
|
+
colorPrimary: '#6366f1',
|
|
563
|
+
colorBackground: '#1e1e2e',
|
|
564
|
+
colorText: '#cdd6f4',
|
|
565
|
+
borderRadius: '0.5rem',
|
|
566
|
+
fontFamily: 'Inter, sans-serif',
|
|
567
|
+
},
|
|
568
|
+
elements: {
|
|
569
|
+
card: 'shadow-xl border border-gray-700',
|
|
570
|
+
formButtonPrimary: 'bg-indigo-600 hover:bg-indigo-700',
|
|
571
|
+
socialButtonsBlockButton: 'border-gray-600',
|
|
572
|
+
},
|
|
573
|
+
}}
|
|
574
|
+
>
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
## Anti-Patterns
|
|
578
|
+
|
|
579
|
+
| Anti-Pattern | Correct Approach |
|
|
580
|
+
|-------------|-----------------|
|
|
581
|
+
| Checking auth client-side only | Always verify auth server-side in middleware and API routes |
|
|
582
|
+
| Storing Clerk user data as source of truth | Sync to your database via webhooks, use your DB as source of truth |
|
|
583
|
+
| Using `unsafeMetadata` for access control | Use Clerk roles and permissions (RBAC), `unsafeMetadata` is user-writable |
|
|
584
|
+
| Not verifying webhook signatures | Always verify with `svix` before processing webhook events |
|
|
585
|
+
| Hardcoding role strings across codebase | Define role/permission constants in a shared module |
|
|
586
|
+
| Using `publicMetadata` for large data | Store large data in your database, use metadata for small flags only |
|
|
587
|
+
| Skipping the `isLoaded` check in hooks | Always check `isLoaded` before accessing user/auth data |
|
|
588
|
+
| Exposing `CLERK_SECRET_KEY` to client | Only `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` goes to the client |
|
|
589
|
+
| Not handling the `user.deleted` webhook | Always clean up your database when a user is deleted |
|
|
590
|
+
| Calling `currentUser()` in frequently-hit API routes | Use `auth()` for just the userId when you do not need the full user object |
|