Skill站外收录 @skilllib/skill-2014279374554476546
clerk-deploy-integration
实现 Clerk 认证应用在 Vercel、Netlify、Railway、Docker 和 AWS Amplify 等平台的一键式生产部署,自动完成环境变量注入、域名配置、Webhook 接入与安全头设置,确保认证流程在真实环境中稳定运行。
开发运维 AI 技能
Skills.MD
# Clerk Deploy Integration
## Overview
Deploy Clerk-authenticated applications to various hosting platforms.
## Prerequisites
- Clerk production instance configured
- Production API keys ready
- Hosting platform account
## Instructions
### Platform 1: Vercel Deployment
#### Step 1: Configure Environment Variables
```bash
# Using Vercel CLI
vercel env add NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY production
vercel env add CLERK_SECRET_KEY production
vercel env add CLERK_WEBHOOK_SECRET production
# Or in vercel.json
```
```json
// vercel.json
{
"env": {
"NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY": "@clerk-publishable-key",
"CLERK_SECRET_KEY": "@clerk-secret-key"
},
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "X-Content-Type-Options", "value": "nosniff" }
]
}
]
}
```
#### Step 2: Configure Clerk Dashboard
1. Add Vercel domain to allowed origins
2. Set production URLs in Clerk Dashboard
3. Configure webhook endpoint
#### Step 3: Deploy
```bash
# Deploy to production
vercel --prod
# Or link to Git for auto-deploy
vercel link
```
### Platform 2: Netlify Deployment
#### Step 1: Configure Environment Variables
```bash
# netlify.toml
[build]
command = "npm run build"
publish = ".next"
[build.environment]
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = "pk_live_..."
# Add secret in Netlify Dashboard
# Site settings > Environment variables > CLERK_SECRET_KEY
```
#### Step 2: Create Netlify Functions for API
```typescript
// netlify/functions/clerk-webhook.ts
import { Handler } from '@netlify/functions'
import { Webhook } from 'svix'
export const handler: Handler = async (event) => {
const WEBHOOK_SECRET = process.env.CLERK_WEBHOOK_SECRET!
const svix_id = event.headers['svix-id']
const svix_timestamp = event.headers['svix-timestamp']
const svix_signature = event.headers['svix-signature']
const wh = new Webhook(WEBHOOK_SECRET)
try {
const evt = wh.verify(event.body!, {
'svix-id': svix_id!,
'svix-timestamp': svix_timestamp!,
'svix-signature': svix_signature!
})
// Process event
return { statusCode: 200, body: JSON.stringify({ success: true }) }
} catch (err) {
return { statusCode: 400, body: 'Invalid signature' }
}
}
```
### Platform 3: Railway Deployment
#### Step 1: Configure Railway
```bash
# railway.json
{
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "npm start",
"healthcheckPath": "/api/health"
}
}
```
#### Step 2: Set Environment Variables
```bash
# Using Railway CLI
railway variables set NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...
railway variables set CLERK_SECRET_KEY=sk_live_...
railway variables set CLERK_WEBHOOK_SECRET=whsec_...
```
### Platform 4: Docker Deployment
#### Dockerfile
```dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# Build-time args for NEXT_PUBLIC_ vars
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# Runtime env vars
ENV CLERK_SECRET_KEY=""
ENV PORT=3000
EXPOSE 3000
CMD ["node", "server.js"]
```
```bash
# Build and run
docker build \
--build-arg NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_... \
-t myapp .
docker run -p 3000:3000 \
-e CLERK_SECRET_KEY=sk_live_... \
myapp
```
### Platform 5: AWS Amplify
```yaml
# amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```
## Clerk Dashboard Configuration
### Production Domain Setup
1. Go to Clerk Dashboard > Configure > Domains
2. Add your production domain
3. Configure SSL (automatic with most platforms)
### Webhook Configuration
1. Go to Clerk Dashboard > Webhooks
2. Add endpoint: `https://yourdomain.com/api/webhooks/clerk`
3. Select events to subscribe
4. Copy webhook secret to environment
### OAuth Redirect URLs
1. Update OAuth providers with production URLs
2. Add `https://yourdomain.com/sso-callback`
3. Remove development URLs for security
## Output
- Platform-specific deployment configuration
- Environment variables configured
- Webhook endpoints ready
- Production domain configured
## Deployment Checklist
- [ ] Production Clerk keys configured
- [ ] Domain added to Clerk Dashboard
- [ ] Webhook endpoint configured
- [ ] OAuth redirect URLs updated
- [ ] SSL/HTTPS enabled
- [ ] Security headers configured
- [ ] Health check endpoint working
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| 500 on sign-in | Missing secret key | Add CLERK_SECRET_KEY to platform |
| Webhook fails | Wrong endpoint URL | Update URL in Clerk Dashboard |
| CORS error | Domain not allowed | Add domain to Clerk allowed origins |
| Redirect loop | Wrong sign-in URL | Check CLERK_SIGN_IN_URL config |
## Resources
- [Vercel Deployment](https://clerk.com/docs/deployments/deploy-to-vercel)
- [Netlify Deployment](https://clerk.com/docs/deployments/deploy-to-netlify)
- [Railway Guide](https://railway.app/docs)
## Next Steps
Proceed to `clerk-webhooks-events` for webhook configuration.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「clerk-deploy-integration」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次