ultra-dex 2.2.1 → 3.2.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/README.md +112 -151
- package/assets/agents/00-AGENT_INDEX.md +1 -1
- package/assets/code-patterns/clerk-middleware.ts +138 -0
- package/assets/code-patterns/prisma-schema.prisma +224 -0
- package/assets/code-patterns/rls-policies.sql +246 -0
- package/assets/code-patterns/server-actions.ts +191 -0
- package/assets/code-patterns/trpc-router.ts +258 -0
- package/assets/cursor-rules/13-ai-integration.mdc +155 -0
- package/assets/cursor-rules/14-server-components.mdc +81 -0
- package/assets/cursor-rules/15-server-actions.mdc +102 -0
- package/assets/cursor-rules/16-edge-middleware.mdc +105 -0
- package/assets/cursor-rules/17-streaming-ssr.mdc +138 -0
- package/assets/docs/LAUNCH-POSTS.md +1 -1
- package/assets/docs/QUICK-REFERENCE.md +9 -4
- package/assets/docs/VISION-V2.md +1 -1
- package/assets/hooks/pre-commit +98 -0
- package/assets/saas-plan/04-Imp-Template.md +1 -1
- package/bin/ultra-dex.js +132 -4
- package/lib/commands/advanced.js +471 -0
- package/lib/commands/agent-builder.js +226 -0
- package/lib/commands/agents.js +102 -42
- package/lib/commands/auto-implement.js +68 -0
- package/lib/commands/banner.js +43 -21
- package/lib/commands/build.js +78 -183
- package/lib/commands/ci-monitor.js +84 -0
- package/lib/commands/config.js +207 -0
- package/lib/commands/dashboard.js +770 -0
- package/lib/commands/diff.js +233 -0
- package/lib/commands/doctor.js +416 -0
- package/lib/commands/export.js +408 -0
- package/lib/commands/fix.js +96 -0
- package/lib/commands/generate.js +105 -78
- package/lib/commands/hooks.js +251 -76
- package/lib/commands/init.js +102 -54
- package/lib/commands/memory.js +80 -0
- package/lib/commands/plan.js +82 -0
- package/lib/commands/review.js +34 -5
- package/lib/commands/run.js +233 -0
- package/lib/commands/scaffold.js +151 -0
- package/lib/commands/serve.js +179 -146
- package/lib/commands/state.js +327 -0
- package/lib/commands/swarm.js +306 -0
- package/lib/commands/sync.js +82 -23
- package/lib/commands/team.js +275 -0
- package/lib/commands/upgrade.js +190 -0
- package/lib/commands/validate.js +34 -0
- package/lib/commands/verify.js +81 -0
- package/lib/commands/watch.js +79 -0
- package/lib/config/theme.js +47 -0
- package/lib/mcp/graph.js +92 -0
- package/lib/mcp/memory.js +95 -0
- package/lib/mcp/resources.js +152 -0
- package/lib/mcp/server.js +34 -0
- package/lib/mcp/tools.js +481 -0
- package/lib/mcp/websocket.js +117 -0
- package/lib/providers/index.js +49 -4
- package/lib/providers/ollama.js +136 -0
- package/lib/providers/router.js +63 -0
- package/lib/quality/scanner.js +128 -0
- package/lib/swarm/coordinator.js +97 -0
- package/lib/swarm/index.js +598 -0
- package/lib/swarm/protocol.js +677 -0
- package/lib/swarm/tiers.js +485 -0
- package/lib/templates/code/clerk-middleware.ts +138 -0
- package/lib/templates/code/prisma-schema.prisma +224 -0
- package/lib/templates/code/rls-policies.sql +246 -0
- package/lib/templates/code/server-actions.ts +191 -0
- package/lib/templates/code/trpc-router.ts +258 -0
- package/lib/templates/custom-agent.md +10 -0
- package/lib/themes/doomsday.js +229 -0
- package/lib/ui/index.js +5 -0
- package/lib/ui/interface.js +241 -0
- package/lib/ui/spinners.js +116 -0
- package/lib/ui/theme.js +183 -0
- package/lib/utils/agents.js +32 -0
- package/lib/utils/files.js +14 -0
- package/lib/utils/graph.js +108 -0
- package/lib/utils/help.js +64 -0
- package/lib/utils/messages.js +35 -0
- package/lib/utils/progress.js +24 -0
- package/lib/utils/prompts.js +47 -0
- package/lib/utils/spinners.js +46 -0
- package/lib/utils/status.js +31 -0
- package/lib/utils/tables.js +41 -0
- package/lib/utils/theme-state.js +9 -0
- package/lib/utils/version-display.js +32 -0
- package/package.json +31 -13
package/README.md
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
# Ultra-Dex CLI
|
|
2
2
|
|
|
3
|
-
> Scaffold Ultra-Dex projects from the command line, now with **AI-powered plan generation
|
|
3
|
+
> Scaffold Ultra-Dex projects from the command line, now with **AI-powered plan generation** and **God Mode** autonomous agents.
|
|
4
4
|
|
|
5
|
-
## What's New in
|
|
5
|
+
## What's New in v3.2.0 (Professional Purple)
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
#
|
|
9
|
-
npx ultra-dex
|
|
8
|
+
# 🤖 Autonomous agent swarms with parallel execution
|
|
9
|
+
npx ultra-dex swarm "Build user authentication" --parallel
|
|
10
10
|
|
|
11
|
-
#
|
|
12
|
-
npx ultra-dex
|
|
11
|
+
# 🔄 Start the Active Kernel (MCP + WebSocket + Dashboard)
|
|
12
|
+
npx ultra-dex serve
|
|
13
13
|
|
|
14
|
-
#
|
|
15
|
-
npx ultra-dex
|
|
14
|
+
# 🧠 Structural Graph Health Check
|
|
15
|
+
npx ultra-dex check
|
|
16
16
|
|
|
17
|
-
#
|
|
18
|
-
npx ultra-dex
|
|
17
|
+
# 🖥️ Live Dashboard with Brain Visualization
|
|
18
|
+
npx ultra-dex dashboard
|
|
19
|
+
|
|
20
|
+
# 🛠️ Self-Healing CI/CD Monitor
|
|
21
|
+
npx ultra-dex ci-monitor --port 3003
|
|
19
22
|
```
|
|
20
23
|
|
|
21
24
|
## First 10 Minutes
|
|
@@ -40,206 +43,164 @@ npm install -g ultra-dex
|
|
|
40
43
|
ultra-dex generate "Your idea"
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
##
|
|
44
|
-
|
|
45
|
-
### `generate` - AI Plan Generation
|
|
46
|
+
## Scaffold Command (NEW)
|
|
46
47
|
|
|
47
|
-
Generate
|
|
48
|
+
Generate production-ready boilerplate instantly:
|
|
48
49
|
|
|
49
50
|
```bash
|
|
50
|
-
#
|
|
51
|
-
npx ultra-dex
|
|
51
|
+
# List available templates
|
|
52
|
+
npx ultra-dex scaffold --list
|
|
52
53
|
|
|
53
|
-
#
|
|
54
|
-
npx ultra-dex
|
|
54
|
+
# Generate Next.js 15 + Prisma + Clerk project
|
|
55
|
+
npx ultra-dex scaffold next15-prisma-clerk
|
|
55
56
|
|
|
56
|
-
#
|
|
57
|
-
npx ultra-dex
|
|
57
|
+
# Generate Remix + Supabase project
|
|
58
|
+
npx ultra-dex scaffold remix-supabase
|
|
59
|
+
|
|
60
|
+
# Generate SvelteKit + Drizzle project
|
|
61
|
+
npx ultra-dex scaffold sveltekit-drizzle
|
|
58
62
|
```
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
| Option | Description | Default |
|
|
62
|
-
|--------|-------------|---------|
|
|
63
|
-
| `-p, --provider` | AI provider (claude, openai, gemini) | claude |
|
|
64
|
-
| `-m, --model` | Specific model to use | provider default |
|
|
65
|
-
| `-o, --output` | Output directory | current |
|
|
66
|
-
| `-k, --key` | API key | env variable |
|
|
67
|
-
| `--dry-run` | Show structure only | false |
|
|
64
|
+
## AI Commands (God Mode)
|
|
68
65
|
|
|
69
|
-
### `
|
|
66
|
+
### `swarm` - Autonomous Agent Pipeline
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
Run complex task pipelines with multiple agents:
|
|
72
69
|
|
|
73
70
|
```bash
|
|
74
|
-
#
|
|
75
|
-
npx ultra-dex
|
|
76
|
-
|
|
77
|
-
# Specific agent
|
|
78
|
-
npx ultra-dex build --agent backend --task "Create user API endpoints"
|
|
71
|
+
# Build a feature with a swarm of agents
|
|
72
|
+
npx ultra-dex swarm "Implement Stripe subscriptions" --parallel
|
|
79
73
|
|
|
80
|
-
#
|
|
81
|
-
npx ultra-dex
|
|
74
|
+
# Dry run to see the plan
|
|
75
|
+
npx ultra-dex swarm "Migrate to Tailwind" --dry-run
|
|
82
76
|
```
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
| Agent | Role |
|
|
86
|
-
|-------|------|
|
|
87
|
-
| `planner` | Break down features into atomic tasks |
|
|
88
|
-
| `cto` | Architecture decisions |
|
|
89
|
-
| `backend` | API endpoints and business logic |
|
|
90
|
-
| `frontend` | UI components and pages |
|
|
91
|
-
| `database` | Schema design and migrations |
|
|
92
|
-
| `auth` | Authentication and authorization |
|
|
93
|
-
| `security` | Security audit |
|
|
94
|
-
| `testing` | Write and run tests |
|
|
95
|
-
| `reviewer` | Code review |
|
|
96
|
-
| `devops` | Deployment and CI/CD |
|
|
78
|
+
### `serve` - Active Kernel
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Check code alignment with plan:
|
|
80
|
+
Start the MCP-compatible server for IDE integration and dashboard:
|
|
101
81
|
|
|
102
82
|
```bash
|
|
103
|
-
npx ultra-dex
|
|
104
|
-
npx ultra-dex review --dir ./src
|
|
83
|
+
npx ultra-dex serve
|
|
105
84
|
```
|
|
106
85
|
|
|
107
|
-
### `
|
|
86
|
+
### `auto-implement` - Autonomous Engineer
|
|
108
87
|
|
|
109
|
-
|
|
88
|
+
Fully autonomous feature implementation loop:
|
|
110
89
|
|
|
111
90
|
```bash
|
|
112
|
-
|
|
113
|
-
npx ultra-dex
|
|
91
|
+
# Implement a feature from scratch
|
|
92
|
+
npx ultra-dex auto-implement "Create a user profile page with Avatar upload"
|
|
114
93
|
```
|
|
115
94
|
|
|
116
|
-
|
|
95
|
+
### `watch` - Real-time Daemon
|
|
96
|
+
|
|
97
|
+
Keep the project state and Code Property Graph updated as you code:
|
|
98
|
+
|
|
117
99
|
```bash
|
|
118
|
-
|
|
119
|
-
OPENAI_API_KEY=sk-... # OpenAI
|
|
120
|
-
GOOGLE_AI_KEY=... # Gemini
|
|
100
|
+
npx ultra-dex watch --interval 1000
|
|
121
101
|
```
|
|
122
102
|
|
|
123
|
-
|
|
103
|
+
## Core Commands
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
### `generate` - AI Plan Generation
|
|
106
|
+
|
|
107
|
+
Generate a complete implementation plan using AI:
|
|
126
108
|
|
|
127
109
|
```bash
|
|
128
|
-
|
|
110
|
+
# Basic usage
|
|
111
|
+
npx ultra-dex generate "A booking platform for dog groomers"
|
|
112
|
+
|
|
113
|
+
# With options
|
|
114
|
+
npx ultra-dex generate "idea" --provider openai --output ./my-project
|
|
129
115
|
```
|
|
130
116
|
|
|
131
|
-
|
|
117
|
+
### `build` - AI-Assisted Development
|
|
132
118
|
|
|
133
|
-
|
|
134
|
-
npx ultra-dex init --live --stack next15-prisma-clerk
|
|
135
|
-
```
|
|
119
|
+
Start development with AI agents (Interactive Mode):
|
|
136
120
|
|
|
137
|
-
|
|
121
|
+
```bash
|
|
122
|
+
# Interactive agent selection
|
|
123
|
+
npx ultra-dex build
|
|
138
124
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
| `-n, --name <name>` | Project name (skips prompt) |
|
|
143
|
-
| `-d, --dir <directory>` | Output directory (default: current) |
|
|
144
|
-
| `--preview` | Preview files without creating them |
|
|
145
|
-
| `--live` | Generate a runnable scaffold |
|
|
146
|
-
| `--stack <preset>` | Preset: next15-prisma-clerk, remix-supabase, sveltekit-drizzle |
|
|
125
|
+
# Specific agent
|
|
126
|
+
npx ultra-dex run backend --task "Create user API endpoints"
|
|
127
|
+
```
|
|
147
128
|
|
|
148
|
-
### `
|
|
129
|
+
### `review` - Graph-Aware Code Review
|
|
149
130
|
|
|
150
|
-
|
|
131
|
+
Audit code against the plan using structural graph analysis:
|
|
151
132
|
|
|
152
133
|
```bash
|
|
153
|
-
npx ultra-dex
|
|
134
|
+
npx ultra-dex review
|
|
154
135
|
```
|
|
155
136
|
|
|
156
|
-
### `
|
|
137
|
+
### `align` - Quick Score
|
|
157
138
|
|
|
158
|
-
|
|
139
|
+
Get alignment score (Files + Plan + Graph Integrity):
|
|
159
140
|
|
|
160
141
|
```bash
|
|
161
|
-
npx ultra-dex
|
|
162
|
-
npx ultra-dex agent backend # Show specific agent
|
|
142
|
+
npx ultra-dex align
|
|
163
143
|
```
|
|
164
144
|
|
|
165
|
-
### `
|
|
145
|
+
### `check` - System Health
|
|
166
146
|
|
|
167
|
-
|
|
147
|
+
Verify repository health and graph consistency:
|
|
168
148
|
|
|
169
149
|
```bash
|
|
170
|
-
npx ultra-dex
|
|
171
|
-
npx ultra-dex fetch --agents --rules
|
|
150
|
+
npx ultra-dex check
|
|
172
151
|
```
|
|
173
152
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Serve context (MCP-compatible):
|
|
153
|
+
## Environment Variables
|
|
177
154
|
|
|
178
155
|
```bash
|
|
179
|
-
|
|
156
|
+
ANTHROPIC_API_KEY=sk-ant-... # Claude (recommended for complex tasks)
|
|
157
|
+
OPENAI_API_KEY=sk-... # OpenAI
|
|
158
|
+
GOOGLE_AI_KEY=... # Gemini
|
|
159
|
+
ULTRA_DEX_DEFAULT_PROVIDER=claude # Default AI provider
|
|
180
160
|
```
|
|
181
161
|
|
|
182
|
-
|
|
162
|
+
## All Commands (38+)
|
|
183
163
|
|
|
184
164
|
| Command | Description |
|
|
185
165
|
|---------|-------------|
|
|
186
166
|
| `init` | Initialize a new project |
|
|
187
|
-
| `
|
|
188
|
-
| `
|
|
167
|
+
| `scaffold` | **NEW** Generate production boilerplate |
|
|
168
|
+
| `generate` | Generate full SaaS plan from idea |
|
|
169
|
+
| `swarm` | Run autonomous agent pipeline |
|
|
170
|
+
| `auto-implement` | Autonomously implement a feature |
|
|
171
|
+
| `serve` | Start the Active Kernel (MCP + Dashboard) |
|
|
172
|
+
| `watch` | Auto-update state on file changes |
|
|
173
|
+
| `build` | Interactive AI agent development loop |
|
|
174
|
+
| `review` | Review code against plan |
|
|
175
|
+
| `align` | Quick alignment score |
|
|
189
176
|
| `audit` | Audit project for completeness |
|
|
190
|
-
| `
|
|
191
|
-
| `
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
196
|
-
| `
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
199
|
-
|
|
|
200
|
-
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Output tokens: ~40,000
|
|
218
|
-
Estimated cost: ~$0.45
|
|
219
|
-
|
|
220
|
-
? Proceed with generation? Yes
|
|
221
|
-
|
|
222
|
-
⚡ Generating 34-section implementation plan...
|
|
223
|
-
|
|
224
|
-
✔ Generation complete!
|
|
225
|
-
|
|
226
|
-
✅ All 34 sections generated
|
|
227
|
-
Tokens used: 42,350 tokens (2,650 in / 39,700 out)
|
|
228
|
-
Actual cost: $0.52
|
|
229
|
-
|
|
230
|
-
📦 Project: GroomBook
|
|
231
|
-
|
|
232
|
-
✓ Created ./IMPLEMENTATION-PLAN.md
|
|
233
|
-
✓ Created ./QUICK-START.md
|
|
234
|
-
✓ Created ./CONTEXT.md
|
|
235
|
-
|
|
236
|
-
🎉 Generation complete!
|
|
237
|
-
|
|
238
|
-
Next steps:
|
|
239
|
-
1. Review IMPLEMENTATION-PLAN.md
|
|
240
|
-
2. Customize sections as needed
|
|
241
|
-
3. Start building with: npx ultra-dex init
|
|
242
|
-
```
|
|
177
|
+
| `validate` | Validate project against 21-step framework |
|
|
178
|
+
| `check` | Verify repository health |
|
|
179
|
+
| `doctor` | Diagnose project issues |
|
|
180
|
+
| `dashboard` | Start the local web dashboard |
|
|
181
|
+
| `sync` | Sync project state across devices |
|
|
182
|
+
| `fetch` | Download assets for offline use |
|
|
183
|
+
| `hooks` | Manage Git hooks |
|
|
184
|
+
| `export` | Export project context |
|
|
185
|
+
| `upgrade` | Check for CLI updates |
|
|
186
|
+
| `config` | Manage CLI and editor configuration |
|
|
187
|
+
| `agents` | List available AI agents |
|
|
188
|
+
| `agent` | Show specific agent prompt |
|
|
189
|
+
| `workflow` | Show specific production workflow |
|
|
190
|
+
| `suggest` | Get AI-powered task suggestions |
|
|
191
|
+
| `plan` | Generate or update implementation plan |
|
|
192
|
+
| `fix` | Automatically fix project issues |
|
|
193
|
+
| `team` | Team collaboration commands |
|
|
194
|
+
| `memory` | Manage long-term agent memory |
|
|
195
|
+
| `verify` | Run executable verification |
|
|
196
|
+
| `ci-monitor` | Self-healing CI/CD listener |
|
|
197
|
+
| `status` | Show project and kernel status |
|
|
198
|
+
| `pre-commit` | Run pre-commit checks |
|
|
199
|
+
| `state` | Manage machine-readable state |
|
|
200
|
+
| `examples` | Access reference workflows |
|
|
201
|
+
| `pack` | Bundle agents and rules |
|
|
202
|
+
| `run` | Execute agent task |
|
|
203
|
+
| `diff` | Compare plan vs implemented code |
|
|
243
204
|
|
|
244
205
|
## Links
|
|
245
206
|
|
|
@@ -250,4 +211,4 @@ Next steps:
|
|
|
250
211
|
|
|
251
212
|
## License
|
|
252
213
|
|
|
253
|
-
MIT
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Ultra-Dex Production Pattern: Clerk Middleware
|
|
2
|
+
// Copy to middleware.ts in your Next.js root
|
|
3
|
+
|
|
4
|
+
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
|
|
5
|
+
import { NextResponse } from 'next/server';
|
|
6
|
+
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// ROUTE MATCHERS
|
|
9
|
+
// =============================================================================
|
|
10
|
+
|
|
11
|
+
// Public routes - accessible without authentication
|
|
12
|
+
const isPublicRoute = createRouteMatcher([
|
|
13
|
+
'/',
|
|
14
|
+
'/sign-in(.*)',
|
|
15
|
+
'/sign-up(.*)',
|
|
16
|
+
'/api/webhooks(.*)',
|
|
17
|
+
'/pricing',
|
|
18
|
+
'/about',
|
|
19
|
+
'/blog(.*)',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
// Admin routes - require admin role
|
|
23
|
+
const isAdminRoute = createRouteMatcher([
|
|
24
|
+
'/admin(.*)',
|
|
25
|
+
'/api/admin(.*)',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
// API routes that need special handling
|
|
29
|
+
const isApiRoute = createRouteMatcher(['/api(.*)']);
|
|
30
|
+
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// MIDDLEWARE
|
|
33
|
+
// =============================================================================
|
|
34
|
+
|
|
35
|
+
export default clerkMiddleware(async (auth, req) => {
|
|
36
|
+
const { userId, sessionClaims } = await auth();
|
|
37
|
+
|
|
38
|
+
// Allow public routes
|
|
39
|
+
if (isPublicRoute(req)) {
|
|
40
|
+
return NextResponse.next();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Protect all non-public routes
|
|
44
|
+
if (!userId) {
|
|
45
|
+
const signInUrl = new URL('/sign-in', req.url);
|
|
46
|
+
signInUrl.searchParams.set('redirect_url', req.url);
|
|
47
|
+
return NextResponse.redirect(signInUrl);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Check admin routes
|
|
51
|
+
if (isAdminRoute(req)) {
|
|
52
|
+
const role = sessionClaims?.metadata?.role as string | undefined;
|
|
53
|
+
|
|
54
|
+
if (role !== 'admin' && role !== 'super_admin') {
|
|
55
|
+
return NextResponse.redirect(new URL('/unauthorized', req.url));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Add user info to headers for API routes
|
|
60
|
+
if (isApiRoute(req)) {
|
|
61
|
+
const requestHeaders = new Headers(req.headers);
|
|
62
|
+
requestHeaders.set('x-user-id', userId);
|
|
63
|
+
|
|
64
|
+
return NextResponse.next({
|
|
65
|
+
request: {
|
|
66
|
+
headers: requestHeaders,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return NextResponse.next();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const config = {
|
|
75
|
+
matcher: [
|
|
76
|
+
// Skip Next.js internals and static files
|
|
77
|
+
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
|
|
78
|
+
// Always run for API routes
|
|
79
|
+
'/(api|trpc)(.*)',
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// USAGE EXAMPLES
|
|
85
|
+
// =============================================================================
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
// In a Server Component - get current user:
|
|
89
|
+
|
|
90
|
+
import { auth, currentUser } from '@clerk/nextjs/server';
|
|
91
|
+
|
|
92
|
+
export default async function DashboardPage() {
|
|
93
|
+
const { userId } = await auth();
|
|
94
|
+
const user = await currentUser();
|
|
95
|
+
|
|
96
|
+
if (!userId) {
|
|
97
|
+
redirect('/sign-in');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return <div>Welcome, {user?.firstName}!</div>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// In a Client Component - use hooks:
|
|
104
|
+
|
|
105
|
+
'use client';
|
|
106
|
+
|
|
107
|
+
import { useUser, useAuth } from '@clerk/nextjs';
|
|
108
|
+
|
|
109
|
+
export function UserProfile() {
|
|
110
|
+
const { user, isLoaded } = useUser();
|
|
111
|
+
const { signOut } = useAuth();
|
|
112
|
+
|
|
113
|
+
if (!isLoaded) return <div>Loading...</div>;
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div>
|
|
117
|
+
<p>Hello, {user?.firstName}</p>
|
|
118
|
+
<button onClick={() => signOut()}>Sign Out</button>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// In an API Route:
|
|
124
|
+
|
|
125
|
+
import { auth } from '@clerk/nextjs/server';
|
|
126
|
+
import { NextResponse } from 'next/server';
|
|
127
|
+
|
|
128
|
+
export async function GET() {
|
|
129
|
+
const { userId } = await auth();
|
|
130
|
+
|
|
131
|
+
if (!userId) {
|
|
132
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Your logic here
|
|
136
|
+
return NextResponse.json({ userId });
|
|
137
|
+
}
|
|
138
|
+
*/
|