workos-knowledge-patch
WorkOS changes since training cutoff (latest: Node SDK v8.10, AuthKit Next.js v3) -- AuthKit proxy/middleware, PKCE, createWorkOS factory, client components, React SPA auth. Load before working with WorkOS.
What this skill does
## Index
| Topic | Reference | Key features |
|---|---|---|
| AuthKit Next.js | [references/authkit-nextjs.md](references/authkit-nextjs.md) | Proxy/middleware, composable auth, client hooks, session management, eager auth, API key validation |
| AuthKit React (SPA) | [references/authkit-react.md](references/authkit-react.md) | Provider setup, sign-in endpoint, multi-org switching, feature flags, token refresh lifecycle |
| Node SDK v8 | [references/node-sdk-v8.md](references/node-sdk-v8.md) | PKCE auth, createWorkOS factory, Cloudflare Workers, breaking changes from v7 |
| Python & Go SDKs | [references/sdk-python-go.md](references/sdk-python-go.md) | WorkOSClient (Python), AsyncWorkOSClient, per-package Go SDK |
---
## Quick Reference
### AuthKit Next.js -- Proxy vs Middleware
| Next.js version | File | Export |
|---|---|---|
| 16+ | `proxy.ts` | `authkitProxy()` |
| <=15 | `middleware.ts` | `authkitMiddleware()` |
For composable proxy/middleware, use `authkit()` + `handleAuthkitHeaders()`:
```ts
import { authkit, handleAuthkitHeaders } from '@workos-inc/authkit-nextjs';
export default async function proxy(request: NextRequest) {
const { session, headers, authorizationUrl } = await authkit(request);
if (!session.user && authorizationUrl) {
return handleAuthkitHeaders(request, headers, { redirect: authorizationUrl });
}
return handleAuthkitHeaders(request, headers);
}
```
For rewrites, use `partitionAuthkitHeaders()` + `applyResponseHeaders()` instead.
### Custom State Through Auth Flow
Pass custom data through OAuth via `state` parameter:
```ts
const signInUrl = await getSignInUrl({
state: JSON.stringify({ teamId: 'team_123', referrer: 'homepage' }),
});
export const GET = handleAuth({
onSuccess: async ({ user, state }) => {
const data = state ? JSON.parse(state) : null;
},
});
```
### Session Refresh Callbacks
```ts
const { session, headers } = await authkit(request, {
onSessionRefreshSuccess: async ({ accessToken, user, impersonator }) => { /* ... */ },
onSessionRefreshError: async ({ error, request }) => { /* ... */ },
});
```
### AuthKit Client Components
All client-side imports use the `/components` subpath:
```tsx
import { AuthKitProvider, Impersonation } from '@workos-inc/authkit-nextjs/components';
import { useAuth, useAccessToken } from '@workos-inc/authkit-nextjs/components';
```
### Node SDK v8 -- Client Types
```ts
import { createWorkOS } from '@workos-inc/node';
// Public client (PKCE only, no server APIs)
const pub = createWorkOS({ clientId: 'client_123' });
// Confidential client (full API access)
const srv = createWorkOS({ apiKey: 'sk_...', clientId: 'client_123' });
```
For Cloudflare Workers: `import { WorkOS } from '@workos-inc/node/worker';`
### PKCE Authentication (Public Clients)
```ts
const workos = new WorkOS({ clientId: 'client_123' }); // no apiKey
const { url, state, codeVerifier } =
await workos.userManagement.getAuthorizationUrlWithPKCE({
redirectUri: 'myapp://callback',
provider: 'authkit',
});
// After callback:
const { accessToken, refreshToken, user } =
await workos.userManagement.authenticateWithCode({
code: authCode,
codeVerifier, // required for PKCE
});
```
### Key Breaking Changes (v7 to v8)
| Area | Change |
|---|---|
| Runtime | Node.js 20+ required (was 16+) |
| SSO | `getAuthorizationUrl` options: discriminated union -- specify one of `connection`, `organization`, `provider` |
| Directory Sync | User fields (`emails`, `username`, `jobTitle`) moved to `customAttributes` |
| MFA | `verifyFactor()` renamed to `verifyChallenge()` |
| Vault | All `*Secret()` methods renamed to `*Object()` |
| PKCE | Always enabled in AuthKit v3 -- remove `WORKOS_ENABLE_PKCE` env var |
### User Management Renames (v7 to v8)
| v7 | v8 |
|---|---|
| `sendMagicAuthCode()` | `createMagicAuth()` |
| `sendPasswordResetEmail()` | `createPasswordReset()` |
| `refreshAndSealSessionData()` | `loadSealedSession()` then `session.refresh()` |
### AuthKit React (SPA) Essentials
Wrap app in `AuthKitProvider` with `clientId`. Set `apiHostname` for custom auth domains in production.
```tsx
import { useAuth } from '@workos-inc/authkit-react';
const { user, signIn, signOut, role, roles, featureFlags, permissions } = useAuth();
// Multi-org switching
const { switchToOrganization } = useAuth();
await switchToOrganization({ organizationId: 'org_123' });
```
Token refresh control: `onBeforeAutoRefresh: () => boolean`, `onRefreshFailure: ({ signIn }) => void`, `refreshBufferInterval: number`.
### Python & Go SDK Patterns
```python
# Python -- uses WorkOSClient, not WorkOS
from workos import WorkOSClient
client = WorkOSClient(api_key="sk_1234", client_id="client_1234")
# Async
from workos import AsyncWorkOSClient
async_client = AsyncWorkOSClient(api_key="sk_1234", client_id="client_1234")
```
```go
// Go v6 -- per-package configuration, no unified client
import "github.com/workos/workos-go/v6/pkg/sso"
sso.Configure("<API_KEY>", "<CLIENT_ID>")
```
---
## Reference Files
| File | Contents |
|---|---|
| [authkit-nextjs.md](references/authkit-nextjs.md) | Proxy migration, composable middleware, client hooks, useAccessToken, session callbacks, eager auth, validateApiKey, saveSession |
| [authkit-react.md](references/authkit-react.md) | SPA provider, sign-in endpoint, multi-org, feature flags, getClaims, token refresh, URL helpers |
| [node-sdk-v8.md](references/node-sdk-v8.md) | PKCE auth, createWorkOS factory, Cloudflare Workers, all breaking changes v7 to v8, post-v8 additions |
| [sdk-python-go.md](references/sdk-python-go.md) | Python WorkOSClient/AsyncWorkOSClient, Go per-package SDK pattern |
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.