workos 0.8.2 → 0.10.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.
Files changed (70) hide show
  1. package/README.md +10 -8
  2. package/dist/bin.js +62 -27
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/auth-status.d.ts +1 -0
  5. package/dist/commands/auth-status.js +56 -0
  6. package/dist/commands/auth-status.js.map +1 -0
  7. package/dist/commands/install-skill.d.ts +0 -1
  8. package/dist/commands/install-skill.js +2 -10
  9. package/dist/commands/install-skill.js.map +1 -1
  10. package/dist/commands/list-skills.d.ts +4 -0
  11. package/dist/commands/list-skills.js +52 -0
  12. package/dist/commands/list-skills.js.map +1 -0
  13. package/dist/commands/login.js +5 -4
  14. package/dist/commands/login.js.map +1 -1
  15. package/dist/commands/uninstall-skill.d.ts +11 -0
  16. package/dist/commands/uninstall-skill.js +116 -0
  17. package/dist/commands/uninstall-skill.js.map +1 -0
  18. package/dist/doctor/checks/ai-analysis.js +3 -3
  19. package/dist/doctor/checks/ai-analysis.js.map +1 -1
  20. package/dist/integrations/dotnet/index.js +7 -12
  21. package/dist/integrations/dotnet/index.js.map +1 -1
  22. package/dist/integrations/elixir/index.js +7 -13
  23. package/dist/integrations/elixir/index.js.map +1 -1
  24. package/dist/integrations/go/index.js +5 -11
  25. package/dist/integrations/go/index.js.map +1 -1
  26. package/dist/integrations/python/index.js +7 -13
  27. package/dist/integrations/python/index.js.map +1 -1
  28. package/dist/integrations/ruby/index.js +9 -14
  29. package/dist/integrations/ruby/index.js.map +1 -1
  30. package/dist/lib/adapters/cli-adapter.js +1 -1
  31. package/dist/lib/adapters/cli-adapter.js.map +1 -1
  32. package/dist/lib/agent-interface.js +10 -9
  33. package/dist/lib/agent-interface.js.map +1 -1
  34. package/dist/lib/agent-runner.js +24 -19
  35. package/dist/lib/agent-runner.js.map +1 -1
  36. package/dist/lib/credential-proxy.js +1 -1
  37. package/dist/lib/credential-proxy.js.map +1 -1
  38. package/dist/lib/ensure-auth.js +3 -3
  39. package/dist/lib/ensure-auth.js.map +1 -1
  40. package/dist/lib/run-with-core.js +1 -1
  41. package/dist/lib/run-with-core.js.map +1 -1
  42. package/dist/lib/token-refresh-client.js +1 -1
  43. package/dist/lib/token-refresh-client.js.map +1 -1
  44. package/dist/lib/token-refresh.js +1 -1
  45. package/dist/lib/token-refresh.js.map +1 -1
  46. package/dist/lib/version-check.js +2 -1
  47. package/dist/lib/version-check.js.map +1 -1
  48. package/dist/utils/exit-codes.js +1 -1
  49. package/dist/utils/exit-codes.js.map +1 -1
  50. package/dist/utils/help-json.js +62 -23
  51. package/dist/utils/help-json.js.map +1 -1
  52. package/package.json +2 -3
  53. package/.claude-plugin/plugin.json +0 -13
  54. package/skills/workos-authkit-base/SKILL.md +0 -123
  55. package/skills/workos-authkit-nextjs/SKILL.md +0 -247
  56. package/skills/workos-authkit-react/SKILL.md +0 -91
  57. package/skills/workos-authkit-react-router/SKILL.md +0 -107
  58. package/skills/workos-authkit-sveltekit/SKILL.md +0 -160
  59. package/skills/workos-authkit-tanstack-start/SKILL.md +0 -300
  60. package/skills/workos-authkit-vanilla-js/SKILL.md +0 -83
  61. package/skills/workos-dotnet/SKILL.md +0 -163
  62. package/skills/workos-elixir/SKILL.md +0 -194
  63. package/skills/workos-go/SKILL.md +0 -191
  64. package/skills/workos-kotlin/SKILL.md +0 -161
  65. package/skills/workos-management/SKILL.md +0 -250
  66. package/skills/workos-node/SKILL.md +0 -164
  67. package/skills/workos-php/SKILL.md +0 -127
  68. package/skills/workos-php-laravel/SKILL.md +0 -147
  69. package/skills/workos-python/SKILL.md +0 -159
  70. package/skills/workos-ruby/SKILL.md +0 -163
@@ -1,123 +0,0 @@
1
- ---
2
- name: workos-authkit-base
3
- description: Architectural reference for WorkOS AuthKit integrations. Fetch README first for implementation details.
4
- ---
5
-
6
- # WorkOS AuthKit Base Template
7
-
8
- ## First Action: Fetch README
9
-
10
- Before any implementation, fetch the framework-specific README:
11
-
12
- ```
13
- WebFetch: {sdk-package-name} README from npmjs.com or GitHub
14
- ```
15
-
16
- README is the source of truth for: install commands, imports, API usage, code patterns.
17
-
18
- ## Task Structure (Required)
19
-
20
- | Phase | Task | Blocked By | Purpose |
21
- | ----- | --------- | ------------------ | --------------------------------- |
22
- | 1 | preflight | - | Verify env vars, detect framework |
23
- | 2 | install | preflight | Install SDK package |
24
- | 3 | callback | install | Create OAuth callback route |
25
- | 4 | provider | install | Setup auth context/middleware |
26
- | 5 | ui | callback, provider | Add sign-in/out UI |
27
- | 6 | verify | ui | Build confirmation |
28
-
29
- ## Decision Trees
30
-
31
- ### Package Manager Detection
32
-
33
- ```
34
- pnpm-lock.yaml? → pnpm
35
- yarn.lock? → yarn
36
- bun.lockb? → bun
37
- else → npm
38
- ```
39
-
40
- ### Provider vs Middleware
41
-
42
- ```
43
- Client-side framework? → AuthKitProvider wraps app
44
- Server-side framework? → Middleware handles sessions
45
- Hybrid (Next.js)? → Both may be needed
46
- ```
47
-
48
- ### Callback Route Location
49
-
50
- Extract path from `WORKOS_REDIRECT_URI` → create route at that exact path.
51
-
52
- ## Environment Variables
53
-
54
- | Variable | Purpose | When Required |
55
- | ------------------------ | ------------------------------ | ------------- |
56
- | `WORKOS_API_KEY` | Server authentication | Server SDKs |
57
- | `WORKOS_CLIENT_ID` | Client identification | All SDKs |
58
- | `WORKOS_REDIRECT_URI` | OAuth callback URL | Server SDKs |
59
- | `WORKOS_COOKIE_PASSWORD` | Session encryption (32+ chars) | Server SDKs |
60
-
61
- Note: Some frameworks use prefixed variants (e.g., `NEXT_PUBLIC_*`). Check README.
62
-
63
- ## Verification Checklists
64
-
65
- ### After Install
66
-
67
- - [ ] SDK package installed in node_modules
68
- - [ ] No install errors in output
69
-
70
- ### After Callback Route
71
-
72
- - [ ] Route file exists at path matching `WORKOS_REDIRECT_URI`
73
- - [ ] Imports SDK callback handler (not custom OAuth)
74
-
75
- ### After Provider/Middleware
76
-
77
- - [ ] Provider wraps entire app (client-side)
78
- - [ ] Middleware configured in correct location (server-side)
79
-
80
- ### After UI
81
-
82
- - [ ] Home page shows conditional auth state
83
- - [ ] Uses SDK functions for sign-in/out URLs
84
-
85
- ### Final Verification
86
-
87
- - [ ] Build completes with exit code 0
88
- - [ ] No import resolution errors
89
-
90
- ## Error Recovery
91
-
92
- ### Module not found
93
-
94
- - [ ] Verify install completed successfully
95
- - [ ] Verify SDK exists in node_modules
96
- - [ ] Re-run install if missing
97
-
98
- ### Build import errors
99
-
100
- - [ ] Delete `node_modules`, reinstall
101
- - [ ] Verify package.json has SDK dependency
102
-
103
- ### Invalid redirect URI
104
-
105
- - [ ] Compare route path to `WORKOS_REDIRECT_URI`
106
- - [ ] Paths must match exactly
107
-
108
- ### Cookie password error
109
-
110
- - [ ] Verify `WORKOS_COOKIE_PASSWORD` is 32+ characters
111
- - [ ] Generate new: `openssl rand -base64 32`
112
-
113
- ### Auth state not persisting
114
-
115
- - [ ] Verify provider wraps entire app
116
- - [ ] Check middleware is in correct location
117
-
118
- ## Critical Rules
119
-
120
- 1. **Install SDK before writing imports** - never create import statements for uninstalled packages
121
- 2. **Use SDK functions** - never construct OAuth URLs manually
122
- 3. **Follow README patterns** - SDK APIs change between versions
123
- 4. **Extract callback path from env** - don't hardcode `/auth/callback`
@@ -1,247 +0,0 @@
1
- ---
2
- name: workos-authkit-nextjs
3
- description: Integrate WorkOS AuthKit with Next.js App Router (13+). Server-side rendering required.
4
- ---
5
-
6
- # WorkOS AuthKit for Next.js
7
-
8
- ## Step 1: Fetch SDK Documentation (BLOCKING)
9
-
10
- **STOP. Do not proceed until complete.**
11
-
12
- WebFetch: `https://github.com/workos/authkit-nextjs/blob/main/README.md`
13
-
14
- The README is the source of truth. If this skill conflicts with README, follow README.
15
-
16
- ## Step 2: Pre-Flight Validation
17
-
18
- ### Project Structure
19
-
20
- - Confirm `next.config.js` or `next.config.mjs` exists
21
- - Confirm `package.json` contains `"next"` dependency
22
-
23
- ### Environment Variables
24
-
25
- Check `.env.local` for:
26
-
27
- - `WORKOS_API_KEY` - starts with `sk_`
28
- - `WORKOS_CLIENT_ID` - starts with `client_`
29
- - `NEXT_PUBLIC_WORKOS_REDIRECT_URI` - valid callback URL
30
- - `WORKOS_COOKIE_PASSWORD` - 32+ characters
31
-
32
- ## Step 3: Install SDK
33
-
34
- Detect package manager, install SDK package from README.
35
-
36
- **Verify:** SDK package exists in node_modules before continuing.
37
-
38
- ## Step 4: Locate the app/ directory (BLOCKING)
39
-
40
- **STOP. Do this before creating any files.**
41
-
42
- Determine where the `app/` directory lives:
43
-
44
- ```bash
45
- # Check for src/app/ first, then root app/
46
- ls src/app/ 2>/dev/null && echo "APP_DIR=src" || (ls app/ 2>/dev/null && echo "APP_DIR=root")
47
- ```
48
-
49
- Set `APP_DIR` for all subsequent steps. All middleware/proxy files MUST be created in `APP_DIR`:
50
-
51
- - If `APP_DIR=src` → create files in `src/` (e.g., `src/proxy.ts`)
52
- - If `APP_DIR=root` → create files at project root (e.g., `proxy.ts`)
53
-
54
- Next.js only discovers middleware/proxy files in the parent directory of `app/`. A file at the wrong level is **silently ignored** — no error, just doesn't run.
55
-
56
- ## Step 5: Version Detection (Decision Tree)
57
-
58
- Read Next.js version from `package.json`:
59
-
60
- ```
61
- Next.js version?
62
- |
63
- +-- 16+ --> Create {APP_DIR}/proxy.ts
64
- |
65
- +-- 15 --> Create {APP_DIR}/middleware.ts (cookies() is async)
66
- |
67
- +-- 13-14 --> Create {APP_DIR}/middleware.ts (cookies() is sync)
68
- ```
69
-
70
- **Next.js 16+ proxy.ts:** `proxy.ts` is the preferred convention. `middleware.ts` still works but shows a deprecation warning. Next.js 16 throws **error E900** if both files exist at the same level.
71
-
72
- **Next.js 15+ async note:** All route handlers and middleware accessing cookies must be async and properly await cookie operations. This is a breaking change from Next.js 14.
73
-
74
- Middleware/proxy code: See README for `authkitMiddleware()` export pattern.
75
-
76
- ### Existing Middleware (IMPORTANT)
77
-
78
- If `middleware.ts` already exists with custom logic (rate limiting, logging, headers, etc.), use the **`authkit()` composable function** instead of `authkitMiddleware`.
79
-
80
- **Pattern for composing with existing middleware:**
81
-
82
- ```typescript
83
- import { NextRequest, NextResponse } from 'next/server';
84
- import { authkit, handleAuthkitHeaders } from '@workos-inc/authkit-nextjs';
85
-
86
- export default async function middleware(request: NextRequest) {
87
- // 1. Get auth session and headers from AuthKit
88
- const { session, headers, authorizationUrl } = await authkit(request);
89
- const { pathname } = request.nextUrl;
90
-
91
- // 2. === YOUR EXISTING MIDDLEWARE LOGIC ===
92
- // Rate limiting, logging, custom headers, etc.
93
- const rateLimitResult = checkRateLimit(request);
94
- if (!rateLimitResult.allowed) {
95
- return new NextResponse('Too Many Requests', { status: 429 });
96
- }
97
-
98
- // 3. Protect routes - redirect to auth if needed
99
- if (pathname.startsWith('/dashboard') && !session.user && authorizationUrl) {
100
- return handleAuthkitHeaders(request, headers, { redirect: authorizationUrl });
101
- }
102
-
103
- // 4. Continue with AuthKit headers properly handled
104
- return handleAuthkitHeaders(request, headers);
105
- }
106
- ```
107
-
108
- **Key functions:**
109
-
110
- - `authkit(request)` - Returns `{ session, headers, authorizationUrl }` for composition
111
- - `handleAuthkitHeaders(request, headers, options?)` - Ensures AuthKit headers pass through correctly
112
- - For rewrites, use `partitionAuthkitHeaders()` and `applyResponseHeaders()` (see README)
113
-
114
- **Critical:** Always return via `handleAuthkitHeaders()` to ensure `withAuth()` works in pages.
115
-
116
- ## Step 6: Create Callback Route
117
-
118
- Parse `NEXT_PUBLIC_WORKOS_REDIRECT_URI` to determine route path:
119
-
120
- ```
121
- URI path --> Route location (use APP_DIR from Step 4)
122
- /auth/callback --> {APP_DIR}/app/auth/callback/route.ts
123
- /callback --> {APP_DIR}/app/callback/route.ts
124
- ```
125
-
126
- Use `handleAuth()` from SDK. Do not write custom OAuth logic.
127
-
128
- **CRITICAL for Next.js 15+:** The route handler MUST be async and properly await handleAuth():
129
-
130
- ```typescript
131
- // CORRECT - Next.js 15+ requires async route handlers
132
- export const GET = handleAuth();
133
-
134
- // If handleAuth returns a function, ensure it's awaited in request context
135
- ```
136
-
137
- Check README for exact usage. If build fails with "cookies outside request scope", the handler is likely missing async/await.
138
-
139
- ## Step 7: Provider Setup (REQUIRED)
140
-
141
- **CRITICAL:** You MUST wrap the app in `AuthKitProvider` in `app/layout.tsx`.
142
-
143
- This is required for:
144
-
145
- - Client-side auth state via `useAuth()` hook
146
- - Consistent auth UX across client/server boundaries
147
- - Proper migration from Auth0 (which uses client-side auth)
148
-
149
- ```tsx
150
- // app/layout.tsx
151
- import { AuthKitProvider } from '@workos-inc/authkit-nextjs/components';
152
-
153
- export default function RootLayout({ children }: { children: React.ReactNode }) {
154
- return (
155
- <html lang="en">
156
- <body>
157
- <AuthKitProvider>{children}</AuthKitProvider>
158
- </body>
159
- </html>
160
- );
161
- }
162
- ```
163
-
164
- **Do NOT skip this step** even if using server-side auth patterns elsewhere.
165
-
166
- ## Step 8: UI Integration
167
-
168
- Add auth UI to `app/page.tsx` using SDK functions. See README for auth helper usage (`withAuth`/`getUser`, `getSignInUrl`, `signOut`).
169
-
170
- **Note:** The SDK renamed `getUser` to `withAuth` in newer versions. Use whichever function the installed SDK version exports — do NOT rename existing working imports.
171
-
172
- ## Verification Checklist (ALL MUST PASS)
173
-
174
- Run these commands to confirm integration. **Do not mark complete until all pass:**
175
-
176
- ```bash
177
- # 1. Check middleware/proxy exists (one should match)
178
- ls proxy.ts middleware.ts src/proxy.ts src/middleware.ts 2>/dev/null
179
-
180
- # 2. CRITICAL: Check AuthKitProvider is in layout (REQUIRED)
181
- grep "AuthKitProvider" app/layout.tsx || echo "FAIL: AuthKitProvider missing from layout"
182
-
183
- # 3. Check callback route exists
184
- find app -name "route.ts" -path "*/callback/*"
185
-
186
- # 4. Build succeeds
187
- npm run build
188
- ```
189
-
190
- **If check #2 fails:** Go back to Step 6 and add AuthKitProvider. This is not optional.
191
-
192
- ## Error Recovery
193
-
194
- ### "cookies was called outside a request scope" (Next.js 15+)
195
-
196
- **Most common cause:** Route handler not properly async or missing await.
197
-
198
- Fix for callback route:
199
-
200
- 1. Check that `handleAuth()` is exported directly: `export const GET = handleAuth();`
201
- 2. If using custom wrapper, ensure it's `async` and awaits any cookie operations
202
- 3. Verify authkit-nextjs SDK version supports Next.js 15+ (check README for compatibility)
203
- 4. **Never** call `cookies()` at module level - only inside request handlers
204
-
205
- This error causes OAuth codes to expire ("invalid_grant"), so fix the handler first.
206
-
207
- ### "middleware.ts not found"
208
-
209
- - Check: File at project root or `src/`, not inside `app/`
210
- - Check: Filename matches Next.js version (proxy.ts for 16+, middleware.ts for 13-15)
211
-
212
- ### "Both middleware file and proxy file are detected" (Next.js 16+)
213
-
214
- - Next.js 16 throws error E900 if both `middleware.ts` and `proxy.ts` exist
215
- - Delete `middleware.ts` and use only `proxy.ts`
216
- - If `middleware.ts` has custom logic, migrate it into `proxy.ts`
217
-
218
- ### "withAuth route not covered by middleware" but middleware/proxy file exists
219
-
220
- - **Most common cause:** File is at the wrong level. Next.js only discovers middleware/proxy files in the parent directory of `app/`. For `src/app/` projects, the file must be in `src/`, not at the project root.
221
- - Check: Is `app/` at `src/app/`? Then middleware/proxy must be at `src/middleware.ts` or `src/proxy.ts`
222
- - Check: Matcher config must include the route path being accessed
223
-
224
- ### "Cannot use getUser in client component"
225
-
226
- - Check: Component has no `'use client'` directive, or
227
- - Check: Move auth logic to server component/API route
228
-
229
- ### "Module not found" for SDK import
230
-
231
- - Check: SDK installed before writing imports
232
- - Check: SDK package directory exists in node_modules
233
-
234
- ### "withAuth route not covered by middleware"
235
-
236
- - Check: Middleware/proxy file exists at correct location
237
- - Check: Matcher config includes the route path
238
-
239
- ### Build fails after AuthKitProvider
240
-
241
- - Check: Import path matches what README specifies (root export vs `/components` subpath)
242
- - Check: No client/server boundary violations
243
-
244
- ### NEXT*PUBLIC* prefix issues
245
-
246
- - Client components need `NEXT_PUBLIC_*` prefix
247
- - Server components use plain env var names
@@ -1,91 +0,0 @@
1
- ---
2
- name: workos-authkit-react
3
- description: Integrate WorkOS AuthKit with React single-page applications. Client-side only authentication. Use when the project is a React SPA without Next.js or React Router.
4
- ---
5
-
6
- # WorkOS AuthKit for React (SPA)
7
-
8
- ## Decision Tree
9
-
10
- ```
11
- START
12
-
13
- ├─► Fetch README (BLOCKING)
14
- │ github.com/workos/authkit-react/blob/main/README.md
15
- │ README is source of truth. Stop if fetch fails.
16
-
17
- ├─► Detect Build Tool
18
- │ ├─ vite.config.ts exists? → Vite
19
- │ └─ otherwise → Create React App
20
-
21
- ├─► Set Env Var Prefix
22
- │ ├─ Vite → VITE_WORKOS_CLIENT_ID
23
- │ └─ CRA → REACT_APP_WORKOS_CLIENT_ID
24
-
25
- └─► Implement per README
26
- ```
27
-
28
- ## Critical: Build Tool Detection
29
-
30
- | Marker File | Build Tool | Env Prefix | Access Pattern |
31
- | ------------------------- | ---------- | ------------ | ------------------------- |
32
- | `vite.config.ts` | Vite | `VITE_` | `import.meta.env.VITE_*` |
33
- | `craco.config.js` or none | CRA | `REACT_APP_` | `process.env.REACT_APP_*` |
34
-
35
- **Wrong prefix = undefined values at runtime.** This is the #1 integration failure.
36
-
37
- ## Key Clarification: No Callback Route
38
-
39
- The React SDK handles OAuth callbacks **internally** via AuthKitProvider.
40
-
41
- - No server-side callback route needed
42
- - SDK intercepts redirect URI client-side
43
- - Token exchange happens automatically
44
-
45
- Just ensure redirect URI env var matches WorkOS Dashboard exactly.
46
-
47
- ## Required Environment Variables
48
-
49
- ```
50
- {PREFIX}WORKOS_CLIENT_ID=client_...
51
- {PREFIX}WORKOS_REDIRECT_URI=http://localhost:5173/callback
52
- ```
53
-
54
- No `WORKOS_API_KEY` needed. Client-side only SDK.
55
-
56
- ## Verification Checklist
57
-
58
- - [ ] README fetched and read
59
- - [ ] Build tool detected correctly
60
- - [ ] Env var prefix matches build tool
61
- - [ ] `.env` or `.env.local` has required vars
62
- - [ ] No `next` dependency (wrong skill)
63
- - [ ] No `react-router` dependency (wrong skill)
64
- - [ ] AuthKitProvider wraps app root
65
- - [ ] `pnpm build` exits 0
66
-
67
- ## Error Recovery
68
-
69
- ### "clientId is required"
70
-
71
- **Cause:** Env var inaccessible (wrong prefix)
72
-
73
- Check: Does prefix match build tool? Vite needs `VITE_`, CRA needs `REACT_APP_`.
74
-
75
- ### Auth state lost on refresh
76
-
77
- **Cause:** Token persistence issue
78
-
79
- Check: Browser dev tools → Application → Local Storage. SDK stores tokens here automatically.
80
-
81
- ### useAuth returns undefined
82
-
83
- **Cause:** Component outside provider tree
84
-
85
- Check: Entry file (`main.tsx` or `index.tsx`) wraps `<App />` in `<AuthKitProvider>`.
86
-
87
- ### Callback redirect fails
88
-
89
- **Cause:** URI mismatch
90
-
91
- Check: Env var redirect URI exactly matches WorkOS Dashboard → Redirects configuration.
@@ -1,107 +0,0 @@
1
- ---
2
- name: workos-authkit-react-router
3
- description: Integrate WorkOS AuthKit with React Router applications. Supports v6 and v7 (Framework, Data, Declarative modes). Use when project uses react-router, react-router-dom, or mentions React Router authentication.
4
- ---
5
-
6
- # WorkOS AuthKit for React Router
7
-
8
- ## Decision Tree
9
-
10
- ```
11
- 1. Fetch README (BLOCKING)
12
- 2. Detect router mode
13
- 3. Follow README for that mode
14
- 4. Verify with checklist below
15
- ```
16
-
17
- ## Phase 1: Fetch SDK Documentation (BLOCKING)
18
-
19
- **STOP - Do not write any code until this completes.**
20
-
21
- WebFetch: `https://github.com/workos/authkit-react-router/blob/main/README.md`
22
-
23
- The README is the source of truth. If this skill conflicts with README, **follow the README**.
24
-
25
- ## Phase 2: Detect Router Mode
26
-
27
- | Mode | Detection Signal | Key Indicator |
28
- | -------------- | ------------------------------- | ------------------------- |
29
- | v7 Framework | `react-router.config.ts` exists | Routes in `app/routes/` |
30
- | v7 Data | `createBrowserRouter` in source | Loaders in route config |
31
- | v7 Declarative | `<BrowserRouter>` component | Routes as JSX, no loaders |
32
- | v6 | package.json version `"6.x"` | Similar to v7 Declarative |
33
-
34
- **Detection order:**
35
-
36
- 1. Check for `react-router.config.ts` (Framework mode)
37
- 2. Grep for `createBrowserRouter` (Data mode)
38
- 3. Check package.json version (v6 vs v7)
39
- 4. Default to Declarative if v7 with `<BrowserRouter>`
40
-
41
- ## Phase 3: Follow README
42
-
43
- Based on detected mode, apply the corresponding README section. The README contains current API signatures and code patterns.
44
-
45
- ## Critical Distinctions
46
-
47
- ### authLoader vs authkitLoader
48
-
49
- | Function | Purpose | Where to use |
50
- | --------------- | ------------------------- | ---------------------- |
51
- | `authLoader` | OAuth callback handler | Callback route ONLY |
52
- | `authkitLoader` | Fetch user data in routes | Any route needing auth |
53
-
54
- **Common mistake:** Using `authkitLoader` for callback route. Use `authLoader()`.
55
-
56
- ### Root Route Requirement
57
-
58
- Auth loader MUST be on root route for child routes to access auth context.
59
-
60
- **Wrong:** Auth loader only on `/dashboard`
61
- **Right:** Auth loader on `/` (root), children inherit context
62
-
63
- ## Environment Variables
64
-
65
- Required in `.env` or `.env.local`:
66
-
67
- - `WORKOS_API_KEY` - starts with `sk_`
68
- - `WORKOS_CLIENT_ID` - starts with `client_`
69
- - `WORKOS_REDIRECT_URI` - full URL (e.g., `http://localhost:3000/auth/callback`)
70
- - `WORKOS_COOKIE_PASSWORD` - 32+ chars (server modes only)
71
-
72
- ## Verification Checklist
73
-
74
- After implementation, verify:
75
-
76
- - [ ] SDK installed in node_modules (package name from README)
77
- - [ ] Callback route path matches `WORKOS_REDIRECT_URI` path segment
78
- - [ ] Auth loader/provider on root route (not just child routes)
79
- - [ ] Build succeeds: `npm run build` exits 0
80
- - [ ] Correct mode pattern applied (loaders vs hooks)
81
-
82
- ## Error Recovery
83
-
84
- ### "loader is not a function"
85
-
86
- **Cause:** Using loader pattern in Declarative/v6 mode
87
- **Fix:** Declarative/v6 modes use `AuthKitProvider` + `useAuth` hook, not loaders
88
-
89
- ### Auth state not available in child routes
90
-
91
- **Cause:** Auth loader missing from root route
92
- **Fix:** Add `authkitLoader` (or `AuthKitProvider`) to root route so children inherit context
93
-
94
- ### useAuth returns undefined
95
-
96
- **Cause:** Missing `AuthKitProvider` wrapper
97
- **Fix:** Wrap app with `AuthKitProvider` (required for Declarative/v6 modes)
98
-
99
- ### Callback route 404
100
-
101
- **Cause:** Route path mismatch with `WORKOS_REDIRECT_URI`
102
- **Fix:** Extract exact path from env var, create route at that path
103
-
104
- ### "Module not found" for SDK
105
-
106
- **Cause:** SDK not installed
107
- **Fix:** Install SDK, wait for completion, verify `node_modules` before writing imports