@mdxui/auth 1.4.1 → 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 CHANGED
@@ -85,6 +85,137 @@ function App() {
85
85
  }
86
86
  ```
87
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
+
88
219
  ### Traditional Setup (Without Shell)
89
220
 
90
221
  ```tsx