@mdxui/auth 1.4.0 → 1.4.2
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 +354 -0
- package/app/assets/index-C6xHcx9J.js +263 -0
- package/app/assets/index-C6xHcx9J.js.map +1 -0
- package/app/assets/index-DunLT2Gt.css +1 -0
- package/app/index.html +15 -0
- package/auth-config.example.json +9 -0
- package/package.json +24 -16
package/README.md
CHANGED
|
@@ -10,6 +10,214 @@ pnpm add @mdxui/auth
|
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
+
### Zero-Config AuthApp (Recommended)
|
|
14
|
+
|
|
15
|
+
The easiest way to get started - just set environment variables:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# .env
|
|
19
|
+
VITE_WORKOS_CLIENT_ID=client_xxx
|
|
20
|
+
VITE_APP_NAME=My App
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { AuthApp } from '@mdxui/auth/shell'
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return <AuthApp />
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
That's it! You get a complete authenticated app with:
|
|
32
|
+
- Sidebar navigation with org switcher
|
|
33
|
+
- Profile, Security, Sessions, API Keys, Team, and Integrations pages
|
|
34
|
+
- Error boundaries with friendly messages
|
|
35
|
+
- Theme support
|
|
36
|
+
|
|
37
|
+
### With Explicit Config
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { AuthApp } from '@mdxui/auth/shell'
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
return (
|
|
44
|
+
<AuthApp
|
|
45
|
+
config={{
|
|
46
|
+
branding: { name: 'My App' },
|
|
47
|
+
identity: {
|
|
48
|
+
clientId: 'client_xxx',
|
|
49
|
+
redirectUri: 'https://myapp.com/callback',
|
|
50
|
+
},
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Custom Routes
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { AuthApp, accountRoutes, developerRoutes } from '@mdxui/auth/shell'
|
|
61
|
+
import { FileText } from 'lucide-react'
|
|
62
|
+
import { DocsPage } from './pages/DocsPage'
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<AuthApp
|
|
67
|
+
config={{
|
|
68
|
+
branding: { name: 'My App' },
|
|
69
|
+
identity: { clientId: 'client_xxx' },
|
|
70
|
+
routes: [
|
|
71
|
+
...accountRoutes, // Profile, Security, Sessions
|
|
72
|
+
...developerRoutes, // API Keys
|
|
73
|
+
{
|
|
74
|
+
key: 'docs',
|
|
75
|
+
path: '/docs',
|
|
76
|
+
label: 'Documentation',
|
|
77
|
+
icon: FileText,
|
|
78
|
+
component: DocsPage,
|
|
79
|
+
group: 'developer',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Prebuilt Static App (Cloudflare Workers / Static Hosting)
|
|
89
|
+
|
|
90
|
+
For deployments where you don't want a build step, use the prebuilt app. The package includes a complete SPA in the `app/` directory with all CSS (Tailwind), React, and routing bundled.
|
|
91
|
+
|
|
92
|
+
#### Option A: Serve with Hono (Recommended)
|
|
93
|
+
|
|
94
|
+
Use Hono to serve the prebuilt app with config injection from environment variables:
|
|
95
|
+
|
|
96
|
+
**wrangler.toml:**
|
|
97
|
+
```toml
|
|
98
|
+
name = "my-auth-app"
|
|
99
|
+
main = "src/index.ts"
|
|
100
|
+
|
|
101
|
+
[assets]
|
|
102
|
+
directory = "node_modules/@mdxui/auth/app"
|
|
103
|
+
|
|
104
|
+
[vars]
|
|
105
|
+
WORKOS_CLIENT_ID = "client_01EXAMPLE"
|
|
106
|
+
APP_NAME = "My App"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**src/index.ts:**
|
|
110
|
+
```ts
|
|
111
|
+
import { Hono } from 'hono'
|
|
112
|
+
|
|
113
|
+
type Bindings = {
|
|
114
|
+
ASSETS: Fetcher
|
|
115
|
+
WORKOS_CLIENT_ID: string
|
|
116
|
+
APP_NAME?: string
|
|
117
|
+
APP_TAGLINE?: string
|
|
118
|
+
LOGO_URL?: string
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const app = new Hono<{ Bindings: Bindings }>()
|
|
122
|
+
|
|
123
|
+
// Serve config from environment variables
|
|
124
|
+
app.get('/auth-config.json', (c) => {
|
|
125
|
+
return c.json({
|
|
126
|
+
clientId: c.env.WORKOS_CLIENT_ID,
|
|
127
|
+
appName: c.env.APP_NAME ?? 'App',
|
|
128
|
+
tagline: c.env.APP_TAGLINE,
|
|
129
|
+
logoUrl: c.env.LOGO_URL,
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Serve static assets (SPA fallback handled by assets)
|
|
134
|
+
app.all('*', async (c) => {
|
|
135
|
+
return c.env.ASSETS.fetch(c.req.raw)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
export default app
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Option B: Vanilla Worker
|
|
142
|
+
|
|
143
|
+
If you're not using Hono, use the standard Worker API:
|
|
144
|
+
|
|
145
|
+
**src/index.ts:**
|
|
146
|
+
```ts
|
|
147
|
+
export interface Env {
|
|
148
|
+
ASSETS: Fetcher
|
|
149
|
+
WORKOS_CLIENT_ID: string
|
|
150
|
+
APP_NAME?: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default {
|
|
154
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
155
|
+
const url = new URL(request.url)
|
|
156
|
+
|
|
157
|
+
// Serve config from environment variables
|
|
158
|
+
if (url.pathname === '/auth-config.json') {
|
|
159
|
+
return Response.json({
|
|
160
|
+
clientId: env.WORKOS_CLIENT_ID,
|
|
161
|
+
appName: env.APP_NAME ?? 'App',
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Serve static assets
|
|
166
|
+
return env.ASSETS.fetch(request)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Both approaches:
|
|
172
|
+
- No copying files needed
|
|
173
|
+
- Config comes from secure environment variables
|
|
174
|
+
- Easy to update by bumping the package version
|
|
175
|
+
|
|
176
|
+
#### Option C: Copy to Static Directory
|
|
177
|
+
|
|
178
|
+
Copy the prebuilt app and add your config file:
|
|
179
|
+
|
|
180
|
+
**1. Install and copy:**
|
|
181
|
+
```bash
|
|
182
|
+
pnpm add @mdxui/auth
|
|
183
|
+
cp -r node_modules/@mdxui/auth/app/* public/
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**2. Create `public/auth-config.json`:**
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"clientId": "client_01EXAMPLE",
|
|
190
|
+
"appName": "My App"
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**3. Configure wrangler.toml:**
|
|
195
|
+
```toml
|
|
196
|
+
name = "my-auth-app"
|
|
197
|
+
|
|
198
|
+
[assets]
|
|
199
|
+
directory = "public"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
This approach:
|
|
203
|
+
- Works with any static hosting (Netlify, Vercel, S3, etc.)
|
|
204
|
+
- Config is a static file in your repo
|
|
205
|
+
- Requires re-copying after package updates
|
|
206
|
+
|
|
207
|
+
#### Config Options
|
|
208
|
+
|
|
209
|
+
| Field | Required | Description |
|
|
210
|
+
|-------|----------|-------------|
|
|
211
|
+
| `clientId` | Yes | WorkOS client ID |
|
|
212
|
+
| `appName` | No | App name (default: "App") |
|
|
213
|
+
| `tagline` | No | Subtitle shown in sidebar |
|
|
214
|
+
| `redirectUri` | No | OAuth redirect URI |
|
|
215
|
+
| `apiHostname` | No | WorkOS API hostname |
|
|
216
|
+
| `devMode` | No | Enable dev mode (default: false) |
|
|
217
|
+
| `logoUrl` | No | URL to logo image |
|
|
218
|
+
|
|
219
|
+
### Traditional Setup (Without Shell)
|
|
220
|
+
|
|
13
221
|
```tsx
|
|
14
222
|
import {
|
|
15
223
|
IdentityProvider,
|
|
@@ -42,6 +250,11 @@ function Dashboard() {
|
|
|
42
250
|
|
|
43
251
|
## Features
|
|
44
252
|
|
|
253
|
+
- **Zero-Config AuthApp** - Complete authenticated app shell with environment variable support
|
|
254
|
+
- **Pre-built Pages** - Profile, Security, Sessions, API Keys, Team, and Integrations pages
|
|
255
|
+
- **Route Presets** - Composable route groups (`accountRoutes`, `developerRoutes`, `adminRoutes`)
|
|
256
|
+
- **SidebarOrgSwitcher** - Auto-wired org switcher with branding fallback
|
|
257
|
+
- **WidgetErrorBoundary** - Friendly, contextual error messages for widget failures
|
|
45
258
|
- **Authentication Providers** - `IdentityProvider` and `AuthGate` for managing auth state
|
|
46
259
|
- **WorkOS Widgets** - Pre-built components for user management (profile, security, API keys)
|
|
47
260
|
- **Vault Components** - UI for managing encrypted secrets with `VaultProvider`
|
|
@@ -111,6 +324,56 @@ import type {
|
|
|
111
324
|
} from '@mdxui/auth'
|
|
112
325
|
```
|
|
113
326
|
|
|
327
|
+
### Shell Exports (`@mdxui/auth/shell`)
|
|
328
|
+
|
|
329
|
+
Complete authenticated app shell with routing:
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
import {
|
|
333
|
+
// App Components
|
|
334
|
+
AuthApp, // Zero-config app with built-in routing
|
|
335
|
+
AuthAppWithChildren, // App shell without routing (bring your own)
|
|
336
|
+
AuthAppProvider, // Providers only (for custom layouts)
|
|
337
|
+
AuthShell, // Shell layout component
|
|
338
|
+
AuthShellNav, // Navigation component
|
|
339
|
+
|
|
340
|
+
// Shell Components
|
|
341
|
+
SidebarOrgSwitcher, // Org switcher with branding fallback
|
|
342
|
+
WidgetErrorBoundary, // Error boundary with friendly messages
|
|
343
|
+
Breadcrumbs, // Breadcrumb navigation
|
|
344
|
+
|
|
345
|
+
// Pre-built Pages
|
|
346
|
+
ProfilePage, // User profile management
|
|
347
|
+
SecurityPage, // Password and MFA settings
|
|
348
|
+
SessionsPage, // Active sessions management
|
|
349
|
+
ApiKeysPage, // API key management
|
|
350
|
+
TeamPage, // Team member management (requires org)
|
|
351
|
+
IntegrationsPage, // Third-party integrations
|
|
352
|
+
|
|
353
|
+
// Route Presets
|
|
354
|
+
defaultRoutes, // All default routes
|
|
355
|
+
defaultGroups, // Default route groups
|
|
356
|
+
accountRoutes, // Profile, Security, Sessions
|
|
357
|
+
developerRoutes, // API Keys
|
|
358
|
+
adminRoutes, // Team management
|
|
359
|
+
integrationRoutes, // Integrations
|
|
360
|
+
|
|
361
|
+
// Config Hooks
|
|
362
|
+
useAuthShellConfig,
|
|
363
|
+
useAuthShellRoutes,
|
|
364
|
+
useAuthShellBranding,
|
|
365
|
+
} from '@mdxui/auth/shell'
|
|
366
|
+
|
|
367
|
+
// Types
|
|
368
|
+
import type {
|
|
369
|
+
AuthAppConfig,
|
|
370
|
+
AuthAppProps,
|
|
371
|
+
AuthAppRoute,
|
|
372
|
+
AuthShellBranding,
|
|
373
|
+
AuthShellIdentity,
|
|
374
|
+
} from '@mdxui/auth/shell'
|
|
375
|
+
```
|
|
376
|
+
|
|
114
377
|
### Subpath Exports
|
|
115
378
|
|
|
116
379
|
For more granular imports:
|
|
@@ -194,6 +457,97 @@ const sessionResult = AuthSessionSchema.safeParse({
|
|
|
194
457
|
})
|
|
195
458
|
```
|
|
196
459
|
|
|
460
|
+
## AuthApp (Shell)
|
|
461
|
+
|
|
462
|
+
### Zero-Config with Environment Variables
|
|
463
|
+
|
|
464
|
+
AuthApp can read configuration from environment variables, perfect for Cloudflare Workers Static Assets:
|
|
465
|
+
|
|
466
|
+
```bash
|
|
467
|
+
# .env
|
|
468
|
+
VITE_WORKOS_CLIENT_ID=client_xxx # Required
|
|
469
|
+
VITE_WORKOS_REDIRECT_URI=https://... # Optional
|
|
470
|
+
VITE_WORKOS_API_HOSTNAME=auth.apis.do # Optional
|
|
471
|
+
VITE_WORKOS_DEV_MODE=true # Optional
|
|
472
|
+
VITE_APP_NAME=My App # Optional (defaults to "App")
|
|
473
|
+
VITE_APP_TAGLINE=Best app ever # Optional
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
```tsx
|
|
477
|
+
import { AuthApp } from '@mdxui/auth/shell'
|
|
478
|
+
|
|
479
|
+
// That's it - reads config from env vars
|
|
480
|
+
function App() {
|
|
481
|
+
return <AuthApp />
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Route Presets
|
|
486
|
+
|
|
487
|
+
Compose routes from presets:
|
|
488
|
+
|
|
489
|
+
```tsx
|
|
490
|
+
import {
|
|
491
|
+
AuthApp,
|
|
492
|
+
accountRoutes, // Profile, Security, Sessions
|
|
493
|
+
developerRoutes, // API Keys
|
|
494
|
+
adminRoutes, // Team
|
|
495
|
+
integrationRoutes, // Integrations
|
|
496
|
+
defaultGroups,
|
|
497
|
+
} from '@mdxui/auth/shell'
|
|
498
|
+
|
|
499
|
+
function App() {
|
|
500
|
+
return (
|
|
501
|
+
<AuthApp
|
|
502
|
+
config={{
|
|
503
|
+
branding: { name: 'My App' },
|
|
504
|
+
identity: { clientId: 'client_xxx' },
|
|
505
|
+
groups: defaultGroups,
|
|
506
|
+
routes: [
|
|
507
|
+
...accountRoutes,
|
|
508
|
+
...developerRoutes,
|
|
509
|
+
// Exclude adminRoutes if you don't need team management
|
|
510
|
+
],
|
|
511
|
+
}}
|
|
512
|
+
/>
|
|
513
|
+
)
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### WidgetErrorBoundary
|
|
518
|
+
|
|
519
|
+
Wraps WorkOS widgets with friendly error handling:
|
|
520
|
+
|
|
521
|
+
```tsx
|
|
522
|
+
import { WidgetErrorBoundary } from '@mdxui/auth/shell'
|
|
523
|
+
import { UserProfile } from '@mdxui/auth/widgets'
|
|
524
|
+
|
|
525
|
+
function ProfilePage() {
|
|
526
|
+
return (
|
|
527
|
+
<WidgetErrorBoundary widgetName="profile">
|
|
528
|
+
<UserProfile authToken={getAccessToken} />
|
|
529
|
+
</WidgetErrorBoundary>
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
// On error: "Your profile is camera shy right now..."
|
|
533
|
+
// Unknown widgets: "Something went wrong loading your API Keys..."
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Custom Sidebar Header
|
|
537
|
+
|
|
538
|
+
```tsx
|
|
539
|
+
import { AuthApp, SidebarOrgSwitcher } from '@mdxui/auth/shell'
|
|
540
|
+
|
|
541
|
+
// Default: SidebarOrgSwitcher is included automatically
|
|
542
|
+
<AuthApp config={config} />
|
|
543
|
+
|
|
544
|
+
// Custom header content
|
|
545
|
+
<AuthApp
|
|
546
|
+
config={config}
|
|
547
|
+
sidebarHeaderContent={<MyCustomHeader />}
|
|
548
|
+
/>
|
|
549
|
+
```
|
|
550
|
+
|
|
197
551
|
## Components
|
|
198
552
|
|
|
199
553
|
### IdentityProvider
|