create-authhero 0.16.0 → 0.18.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 +105 -26
- package/dist/cloudflare-multitenant/README.md +145 -7
- package/dist/cloudflare-multitenant/copy-assets.js +66 -0
- package/dist/cloudflare-multitenant/wrangler.toml +44 -10
- package/dist/cloudflare-simple/README.md +153 -27
- package/dist/cloudflare-simple/copy-assets.js +66 -0
- package/dist/cloudflare-simple/wrangler.toml +44 -10
- package/dist/create-authhero.js +247 -149
- package/dist/local/src/app.ts +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,9 +18,10 @@ The CLI will guide you through:
|
|
|
18
18
|
|
|
19
19
|
1. **Project name** - Name of your project directory
|
|
20
20
|
2. **Setup type** - Choose between Local, Cloudflare Simple, or Cloudflare Multi-Tenant
|
|
21
|
-
3. **
|
|
22
|
-
4. **
|
|
23
|
-
5. **
|
|
21
|
+
3. **GitHub CI** - (Cloudflare only) Optionally include GitHub Actions workflows with semantic versioning
|
|
22
|
+
4. **Admin credentials** - Email and password for the initial admin user
|
|
23
|
+
5. **Install dependencies** - Optionally install packages with your preferred package manager
|
|
24
|
+
6. **Start server** - Optionally run migrations, seed the database, and start the dev server
|
|
24
25
|
|
|
25
26
|
## Setup Types
|
|
26
27
|
|
|
@@ -68,27 +69,38 @@ npm run dev
|
|
|
68
69
|
```
|
|
69
70
|
my-auth-project/
|
|
70
71
|
├── src/
|
|
71
|
-
│ ├── index.ts
|
|
72
|
-
│ ├── app.ts
|
|
73
|
-
│ └── types.ts
|
|
74
|
-
├── wrangler.toml
|
|
75
|
-
├──
|
|
72
|
+
│ ├── index.ts # Worker entry point
|
|
73
|
+
│ ├── app.ts # AuthHero configuration
|
|
74
|
+
│ └── types.ts # TypeScript types
|
|
75
|
+
├── wrangler.toml # Base Cloudflare config (safe for git)
|
|
76
|
+
├── wrangler.local.toml # Your private IDs (gitignored)
|
|
77
|
+
├── .dev.vars # Local secrets (gitignored)
|
|
78
|
+
├── .dev.vars.example # Template for .dev.vars
|
|
79
|
+
├── seed.sql # Database seeding (generated)
|
|
76
80
|
├── package.json
|
|
77
81
|
└── tsconfig.json
|
|
78
82
|
```
|
|
79
83
|
|
|
80
|
-
**Quick Start:**
|
|
84
|
+
**Quick Start (Local Development):**
|
|
81
85
|
|
|
82
86
|
```sh
|
|
83
87
|
cd my-auth-project
|
|
84
88
|
npm install
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
npm run db:migrate
|
|
88
|
-
npm run seed
|
|
89
|
+
npm run migrate
|
|
90
|
+
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed
|
|
89
91
|
npm run dev
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
**Remote Development (Your Cloudflare Account):**
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
# Create a D1 database
|
|
98
|
+
npx wrangler d1 create authhero-db
|
|
99
|
+
# Copy the database_id to wrangler.local.toml
|
|
100
|
+
npm run db:migrate:remote
|
|
101
|
+
npm run dev:remote
|
|
102
|
+
```
|
|
103
|
+
|
|
92
104
|
### 3. Cloudflare Multi-Tenant (Production)
|
|
93
105
|
|
|
94
106
|
**Best for:** SaaS platforms, agencies, enterprise deployments
|
|
@@ -103,13 +115,15 @@ npm run dev
|
|
|
103
115
|
```
|
|
104
116
|
my-auth-project/
|
|
105
117
|
├── src/
|
|
106
|
-
│ ├── index.ts
|
|
107
|
-
│ ├── app.ts
|
|
108
|
-
│ ├── types.ts
|
|
118
|
+
│ ├── index.ts # Worker entry point
|
|
119
|
+
│ ├── app.ts # AuthHero configuration
|
|
120
|
+
│ ├── types.ts # TypeScript types
|
|
109
121
|
│ └── database-factory.ts # Multi-tenant DB factory
|
|
110
|
-
├── wrangler.toml
|
|
111
|
-
├── .
|
|
112
|
-
├──
|
|
122
|
+
├── wrangler.toml # Base Cloudflare config (safe for git)
|
|
123
|
+
├── wrangler.local.toml # Your private IDs (gitignored)
|
|
124
|
+
├── .dev.vars # Local secrets (gitignored)
|
|
125
|
+
├── .dev.vars.example # Environment variables template
|
|
126
|
+
├── seed.sql # Database seeding (generated)
|
|
113
127
|
├── package.json
|
|
114
128
|
└── tsconfig.json
|
|
115
129
|
```
|
|
@@ -138,20 +152,51 @@ my-auth-project/
|
|
|
138
152
|
└─────────────┘ └─────────────┘ └─────────────┘
|
|
139
153
|
```
|
|
140
154
|
|
|
141
|
-
**Quick Start:**
|
|
155
|
+
**Quick Start (Local Development):**
|
|
142
156
|
|
|
143
157
|
```sh
|
|
144
158
|
cd my-auth-project
|
|
145
159
|
npm install
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
cp .dev.vars.example .dev.vars
|
|
149
|
-
# Add your Cloudflare credentials to .dev.vars
|
|
150
|
-
npm run db:migrate
|
|
151
|
-
npm run seed
|
|
160
|
+
npm run migrate
|
|
161
|
+
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed
|
|
152
162
|
npm run dev
|
|
153
163
|
```
|
|
154
164
|
|
|
165
|
+
**Remote Development (Your Cloudflare Account):**
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
# Create a D1 database
|
|
169
|
+
npx wrangler d1 create authhero-db
|
|
170
|
+
# Copy the database_id to wrangler.local.toml
|
|
171
|
+
# Optionally add CLOUDFLARE_ACCOUNT_ID to .dev.vars
|
|
172
|
+
npm run db:migrate:remote
|
|
173
|
+
npm run dev:remote
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Security & Privacy
|
|
177
|
+
|
|
178
|
+
Cloudflare projects are designed to be **open-source friendly**:
|
|
179
|
+
|
|
180
|
+
| File | Purpose | In Git? |
|
|
181
|
+
| --------------------- | ---------------------------------- | ------- |
|
|
182
|
+
| `wrangler.toml` | Base config (safe for public repo) | ✅ Yes |
|
|
183
|
+
| `wrangler.local.toml` | Your private IDs (database_id) | ❌ No |
|
|
184
|
+
| `.dev.vars` | Local secrets (API tokens, etc.) | ❌ No |
|
|
185
|
+
| `.dev.vars.example` | Template for .dev.vars | ✅ Yes |
|
|
186
|
+
|
|
187
|
+
The CLI automatically creates `wrangler.local.toml` and `.dev.vars` from the templates when you create a project. Simply update them with your Cloudflare IDs.
|
|
188
|
+
|
|
189
|
+
### GitHub Actions / CI Deployment
|
|
190
|
+
|
|
191
|
+
For automated deployments, set these GitHub Secrets:
|
|
192
|
+
|
|
193
|
+
| Secret | Description |
|
|
194
|
+
| ----------------------- | -------------------------------------------------------- |
|
|
195
|
+
| `CLOUDFLARE_API_TOKEN` | API token with Workers permissions |
|
|
196
|
+
| `CLOUDFLARE_ACCOUNT_ID` | Your Cloudflare account ID (optional, for some features) |
|
|
197
|
+
|
|
198
|
+
The wrangler GitHub Action will automatically use these secrets. No need to store IDs in your repo!
|
|
199
|
+
|
|
155
200
|
## Example
|
|
156
201
|
|
|
157
202
|
```sh
|
|
@@ -175,6 +220,40 @@ You'll be prompted to:
|
|
|
175
220
|
| Complexity | Low | Medium | High |
|
|
176
221
|
| Best For | Development | Simple Production | Enterprise/SaaS |
|
|
177
222
|
|
|
223
|
+
## GitHub CI with Semantic Versioning
|
|
224
|
+
|
|
225
|
+
For Cloudflare setups, you can optionally include GitHub Actions workflows that provide:
|
|
226
|
+
|
|
227
|
+
- **Unit Tests**: Runs on all pushes to any branch
|
|
228
|
+
- **Deploy to Dev**: Automatically deploys to dev environment on push to `main`, with semantic-release for version management
|
|
229
|
+
- **Deploy to Production**: Deploys to production when a GitHub release is published
|
|
230
|
+
|
|
231
|
+
### CI/CD Flow
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
All PRs/Pushes → Unit Tests (type-check + tests)
|
|
235
|
+
Push to main → Semantic Release + Deploy to Dev
|
|
236
|
+
GitHub Release → Deploy to Production
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Required GitHub Secrets
|
|
240
|
+
|
|
241
|
+
| Secret | Description |
|
|
242
|
+
| --------------------------- | ---------------------------------------- |
|
|
243
|
+
| `CLOUDFLARE_API_TOKEN` | API token for dev deployments |
|
|
244
|
+
| `CLOUDFLARE_ACCOUNT_ID` | Account ID (optional, for some features) |
|
|
245
|
+
| `PROD_CLOUDFLARE_API_TOKEN` | API token for production deployments |
|
|
246
|
+
|
|
247
|
+
> **Note:** You do NOT need to store `database_id` or `zone_id` in your repo or secrets. Wrangler resolves these automatically when deploying with the correct API token.
|
|
248
|
+
|
|
249
|
+
### Commit Message Conventions
|
|
250
|
+
|
|
251
|
+
Use conventional commits for automatic versioning:
|
|
252
|
+
|
|
253
|
+
- `fix:` → Patch release (1.0.0 → 1.0.1)
|
|
254
|
+
- `feat:` → Minor release (1.0.0 → 1.1.0)
|
|
255
|
+
- `BREAKING CHANGE:` → Major release (1.0.0 → 2.0.0)
|
|
256
|
+
|
|
178
257
|
## Documentation
|
|
179
258
|
|
|
180
259
|
For more information, visit [https://authhero.net/docs](https://authhero.net/docs)
|
|
@@ -4,6 +4,7 @@ A production-grade multi-tenant AuthHero authentication server using Cloudflare
|
|
|
4
4
|
|
|
5
5
|
- Multi-tenant support with tenant isolation at the data level
|
|
6
6
|
- Multiple tenants in a single D1 database
|
|
7
|
+
- Static assets (widget, CSS, JS) served via Cloudflare Workers Assets
|
|
7
8
|
- Easy setup similar to single-tenant
|
|
8
9
|
|
|
9
10
|
## Architecture
|
|
@@ -18,6 +19,11 @@ A production-grade multi-tenant AuthHero authentication server using Cloudflare
|
|
|
18
19
|
│ │ - Tenant isolation via API │ │
|
|
19
20
|
│ └─────────────────────────────────┘ │
|
|
20
21
|
│ │ │
|
|
22
|
+
│ ┌───────────┴────────────────────┐ │
|
|
23
|
+
│ │ Static Assets │ │
|
|
24
|
+
│ │ /u/widget/* /u/css/* /u/js/* │ │
|
|
25
|
+
│ └────────────────────────────────┘ │
|
|
26
|
+
│ │ │
|
|
21
27
|
└──────────────┼──────────────────────────┘
|
|
22
28
|
│
|
|
23
29
|
▼
|
|
@@ -28,15 +34,53 @@ A production-grade multi-tenant AuthHero authentication server using Cloudflare
|
|
|
28
34
|
└─────────────┘
|
|
29
35
|
```
|
|
30
36
|
|
|
37
|
+
## Static Assets
|
|
38
|
+
|
|
39
|
+
The authentication widget, CSS, and client-side JavaScript are served as static assets via Cloudflare Workers Assets.
|
|
40
|
+
|
|
41
|
+
### How It Works
|
|
42
|
+
|
|
43
|
+
1. **Source**: Assets are bundled with the `authhero` package in `node_modules/authhero/dist/assets`
|
|
44
|
+
2. **Build Step**: The `copy-assets.js` script copies these files to `./dist/assets` before dev/deploy
|
|
45
|
+
3. **Serving**: Wrangler serves files from `./dist/assets` (configured in `wrangler.toml`)
|
|
46
|
+
4. **Automatic**: The copy happens automatically when you run `npm run dev` or `npm run deploy`
|
|
47
|
+
|
|
48
|
+
> **Note**: Wrangler's Assets feature does not support serving files directly from `node_modules`, which is why the copy step is necessary.
|
|
49
|
+
|
|
50
|
+
Assets are served at:
|
|
51
|
+
|
|
52
|
+
- `/u/widget/*` - AuthHero login widget (Stencil web component)
|
|
53
|
+
- `/u/css/*` - Tailwind CSS for universal login pages
|
|
54
|
+
- `/u/js/*` - Client-side JavaScript bundle
|
|
55
|
+
|
|
56
|
+
## Security & Privacy
|
|
57
|
+
|
|
58
|
+
This project is designed to be **open-source friendly**. Sensitive Cloudflare IDs are kept out of version control:
|
|
59
|
+
|
|
60
|
+
| File | Purpose | In Git? |
|
|
61
|
+
| --------------------- | ---------------------------------- | ------- |
|
|
62
|
+
| `wrangler.toml` | Base config (safe for public repo) | ✅ Yes |
|
|
63
|
+
| `wrangler.local.toml` | Your private IDs (database_id) | ❌ No |
|
|
64
|
+
| `.dev.vars` | Local secrets (API tokens, etc.) | ❌ No |
|
|
65
|
+
| `.dev.vars.example` | Template for .dev.vars | ✅ Yes |
|
|
66
|
+
|
|
67
|
+
**For GitHub Actions / CI:**
|
|
68
|
+
|
|
69
|
+
- Set `CLOUDFLARE_API_TOKEN` as a GitHub Secret
|
|
70
|
+
- Set `CLOUDFLARE_ACCOUNT_ID` as a GitHub Secret (if needed)
|
|
71
|
+
- The wrangler action will use these automatically
|
|
72
|
+
|
|
31
73
|
## Getting Started
|
|
32
74
|
|
|
75
|
+
### Local Development (Quick Start)
|
|
76
|
+
|
|
33
77
|
1. Install dependencies:
|
|
34
78
|
|
|
35
79
|
```bash
|
|
36
80
|
npm install
|
|
37
81
|
```
|
|
38
82
|
|
|
39
|
-
2. Run local
|
|
83
|
+
2. Run database migrations (uses local SQLite-backed D1):
|
|
40
84
|
|
|
41
85
|
```bash
|
|
42
86
|
npm run migrate
|
|
@@ -55,29 +99,46 @@ A production-grade multi-tenant AuthHero authentication server using Cloudflare
|
|
|
55
99
|
|
|
56
100
|
The server will be available at `https://localhost:3000`.
|
|
57
101
|
|
|
58
|
-
|
|
102
|
+
### Remote Development (Your Cloudflare Account)
|
|
59
103
|
|
|
60
104
|
1. Create a D1 database:
|
|
61
105
|
|
|
62
106
|
```bash
|
|
63
|
-
wrangler d1 create authhero-db
|
|
107
|
+
npx wrangler d1 create authhero-db
|
|
64
108
|
```
|
|
65
109
|
|
|
66
|
-
2.
|
|
110
|
+
2. Copy the `database_id` from the output and update `wrangler.local.toml`:
|
|
111
|
+
|
|
112
|
+
```toml
|
|
113
|
+
[[d1_databases]]
|
|
114
|
+
binding = "AUTH_DB"
|
|
115
|
+
database_name = "authhero-db"
|
|
116
|
+
database_id = "paste-your-database-id-here"
|
|
117
|
+
migrations_dir = "node_modules/@authhero/drizzle/drizzle"
|
|
118
|
+
```
|
|
67
119
|
|
|
68
|
-
3. Run migrations
|
|
120
|
+
3. Run remote migrations:
|
|
69
121
|
|
|
70
122
|
```bash
|
|
71
123
|
npm run db:migrate:remote
|
|
72
124
|
```
|
|
73
125
|
|
|
74
|
-
4. Seed the
|
|
126
|
+
4. Seed the remote database:
|
|
75
127
|
|
|
76
128
|
```bash
|
|
77
129
|
ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed:remote
|
|
78
130
|
```
|
|
79
131
|
|
|
80
|
-
5.
|
|
132
|
+
5. Start with remote D1:
|
|
133
|
+
```bash
|
|
134
|
+
npm run dev:remote
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Production Deployment
|
|
138
|
+
|
|
139
|
+
1. Ensure `wrangler.local.toml` has your production `database_id`.
|
|
140
|
+
|
|
141
|
+
2. Deploy:
|
|
81
142
|
```bash
|
|
82
143
|
npm run deploy
|
|
83
144
|
```
|
|
@@ -154,6 +215,83 @@ curl https://your-worker.workers.dev/management/tenants \
|
|
|
154
215
|
|
|
155
216
|
For more information, visit [https://authhero.net/docs](https://authhero.net/docs).
|
|
156
217
|
|
|
218
|
+
## CI/CD with GitHub Actions
|
|
219
|
+
|
|
220
|
+
If you selected GitHub CI during setup, your project includes automated workflows for continuous integration and deployment.
|
|
221
|
+
|
|
222
|
+
### Workflow Overview
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
226
|
+
│ GitHub Actions │
|
|
227
|
+
├─────────────────────────────────────────────────────────────────────────┤
|
|
228
|
+
│ │
|
|
229
|
+
│ ┌──────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
|
|
230
|
+
│ │ Any Push │ │ Push to main │ │ GitHub Release │ │
|
|
231
|
+
│ │ │ │ │ │ (released) │ │
|
|
232
|
+
│ └──────┬───────┘ └────────┬─────────┘ └────────┬─────────┘ │
|
|
233
|
+
│ │ │ │ │
|
|
234
|
+
│ ▼ ▼ ▼ │
|
|
235
|
+
│ ┌──────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
|
|
236
|
+
│ │ Unit Tests │ │ Semantic Release │ │ Deploy to │ │
|
|
237
|
+
│ │ Type Check │ │ + Deploy Dev │ │ Production │ │
|
|
238
|
+
│ └──────────────┘ └──────────────────┘ └──────────────────┘ │
|
|
239
|
+
│ │
|
|
240
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Workflows
|
|
244
|
+
|
|
245
|
+
1. **Unit Tests** (`.github/workflows/unit-tests.yml`)
|
|
246
|
+
- **Trigger**: All pushes to any branch
|
|
247
|
+
- **Actions**: Runs type checking and tests
|
|
248
|
+
|
|
249
|
+
2. **Deploy to Dev** (`.github/workflows/deploy-dev.yml`)
|
|
250
|
+
- **Trigger**: Push to `main` branch
|
|
251
|
+
- **Actions**:
|
|
252
|
+
- Runs semantic-release to create version tags
|
|
253
|
+
- Deploys to Cloudflare Workers (dev environment)
|
|
254
|
+
|
|
255
|
+
3. **Deploy to Production** (`.github/workflows/release.yml`)
|
|
256
|
+
- **Trigger**: GitHub Release (when "released")
|
|
257
|
+
- **Actions**: Deploys to Cloudflare Workers (production environment)
|
|
258
|
+
|
|
259
|
+
### Required Secrets
|
|
260
|
+
|
|
261
|
+
Configure these secrets in your GitHub repository settings:
|
|
262
|
+
|
|
263
|
+
| Secret | Description |
|
|
264
|
+
| --------------------------- | ----------------------------------------------- |
|
|
265
|
+
| `CLOUDFLARE_API_TOKEN` | Cloudflare API token for dev deployments |
|
|
266
|
+
| `PROD_CLOUDFLARE_API_TOKEN` | Cloudflare API token for production deployments |
|
|
267
|
+
|
|
268
|
+
### Semantic Versioning
|
|
269
|
+
|
|
270
|
+
Commits to `main` are analyzed to determine version bumps:
|
|
271
|
+
|
|
272
|
+
- `fix:` - Patch release (1.0.0 → 1.0.1)
|
|
273
|
+
- `feat:` - Minor release (1.0.0 → 1.1.0)
|
|
274
|
+
- `BREAKING CHANGE:` - Major release (1.0.0 → 2.0.0)
|
|
275
|
+
|
|
276
|
+
### Production Deployment
|
|
277
|
+
|
|
278
|
+
To deploy to production:
|
|
279
|
+
|
|
280
|
+
1. Go to GitHub → Releases → "Draft a new release"
|
|
281
|
+
2. Create a new tag (e.g., `v1.0.0`)
|
|
282
|
+
3. Click "Publish release"
|
|
283
|
+
4. The `release.yml` workflow will deploy to production
|
|
284
|
+
|
|
285
|
+
### Wrangler Configuration
|
|
286
|
+
|
|
287
|
+
For production deployments, add an environment to `wrangler.toml`:
|
|
288
|
+
|
|
289
|
+
```toml
|
|
290
|
+
[env.production]
|
|
291
|
+
name = "your-worker-production"
|
|
292
|
+
# Add production-specific settings here
|
|
293
|
+
```
|
|
294
|
+
|
|
157
295
|
## Optional Features
|
|
158
296
|
|
|
159
297
|
### Analytics Engine (Centralized Logging)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copy AuthHero assets to dist directory
|
|
5
|
+
*
|
|
6
|
+
* This script copies static assets from the authhero package to the dist directory
|
|
7
|
+
* so they can be served by Wrangler's Assets feature. Wrangler does not support
|
|
8
|
+
* serving files directly from node_modules.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
|
|
18
|
+
const sourceDir = path.join(
|
|
19
|
+
__dirname,
|
|
20
|
+
"node_modules",
|
|
21
|
+
"authhero",
|
|
22
|
+
"dist",
|
|
23
|
+
"assets",
|
|
24
|
+
);
|
|
25
|
+
const targetDir = path.join(__dirname, "dist", "assets");
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Recursively copy directory contents
|
|
29
|
+
*/
|
|
30
|
+
function copyDirectory(src, dest) {
|
|
31
|
+
// Create destination directory if it doesn't exist
|
|
32
|
+
if (!fs.existsSync(dest)) {
|
|
33
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Read source directory
|
|
37
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
38
|
+
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const srcPath = path.join(src, entry.name);
|
|
41
|
+
const destPath = path.join(dest, entry.name);
|
|
42
|
+
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
copyDirectory(srcPath, destPath);
|
|
45
|
+
} else {
|
|
46
|
+
fs.copyFileSync(srcPath, destPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
console.log("📦 Copying AuthHero assets...");
|
|
53
|
+
|
|
54
|
+
if (!fs.existsSync(sourceDir)) {
|
|
55
|
+
console.error(`❌ Source directory not found: ${sourceDir}`);
|
|
56
|
+
console.error("Make sure the authhero package is installed.");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
copyDirectory(sourceDir, targetDir);
|
|
61
|
+
|
|
62
|
+
console.log(`✅ Assets copied to ${targetDir}`);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("❌ Error copying assets:", error.message);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
@@ -1,23 +1,57 @@
|
|
|
1
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
# AuthHero Multi-Tenant Cloudflare Worker Configuration
|
|
3
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
4
|
+
# This file is safe for version control. Sensitive IDs should go in:
|
|
5
|
+
# - wrangler.local.toml (local development - gitignored)
|
|
6
|
+
# - GitHub Secrets / Cloudflare Dashboard (production)
|
|
7
|
+
#
|
|
8
|
+
# For local development with your own Cloudflare resources:
|
|
9
|
+
# cp wrangler.toml wrangler.local.toml
|
|
10
|
+
# # Add your database_id to wrangler.local.toml
|
|
11
|
+
# npm run dev # Uses wrangler.local.toml automatically
|
|
12
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
13
|
+
|
|
1
14
|
name = "authhero-multitenant"
|
|
2
15
|
main = "src/index.ts"
|
|
3
16
|
compatibility_date = "2024-11-20"
|
|
4
17
|
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
18
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
19
|
+
# Static Assets (CSS, JS, Widget)
|
|
20
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
21
|
+
# Serve static assets from the authhero package.
|
|
22
|
+
# This includes the widget, CSS, and client-side JavaScript.
|
|
23
|
+
# Assets are copied from node_modules/authhero/dist/assets to dist/assets
|
|
24
|
+
# during the build process (see copy-assets.js).
|
|
25
|
+
# Assets are served at their path: /u/widget/*, /u/css/*, /u/js/*
|
|
26
|
+
[assets]
|
|
27
|
+
directory = "./dist/assets"
|
|
13
28
|
|
|
14
|
-
#
|
|
29
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
30
|
+
# D1 Database binding
|
|
31
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
32
|
+
# This configuration uses a local D1 database by default.
|
|
33
|
+
# For remote development/production, copy to wrangler.local.toml and update.
|
|
34
|
+
#
|
|
35
|
+
# Setup:
|
|
36
|
+
# 1. Create database: npx wrangler d1 create authhero-db
|
|
37
|
+
# 2. Copy to local config: cp wrangler.toml wrangler.local.toml
|
|
38
|
+
# 3. Update database_id in wrangler.local.toml with the ID from step 1
|
|
39
|
+
#
|
|
15
40
|
[[d1_databases]]
|
|
16
41
|
binding = "AUTH_DB"
|
|
17
42
|
database_name = "authhero-db"
|
|
18
|
-
database_id = "local"
|
|
43
|
+
database_id = "local" # Use "local" for local dev, or your actual ID in wrangler.local.toml
|
|
19
44
|
migrations_dir = "node_modules/@authhero/drizzle/drizzle"
|
|
20
45
|
|
|
46
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
47
|
+
# OPTIONAL: Custom Domain
|
|
48
|
+
# ════════════════════════════════════════════════════════════════════════════
|
|
49
|
+
# To route your worker to a custom domain, use zone_name (not zone_id):
|
|
50
|
+
#
|
|
51
|
+
# [[routes]]
|
|
52
|
+
# pattern = "auth.yourdomain.com/*"
|
|
53
|
+
# zone_name = "yourdomain.com"
|
|
54
|
+
|
|
21
55
|
# ════════════════════════════════════════════════════════════════════════════
|
|
22
56
|
# OPTIONAL: Analytics Engine for centralized logging
|
|
23
57
|
# ════════════════════════════════════════════════════════════════════════════
|