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/dist/create-authhero.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { spawn as
|
|
7
|
-
const
|
|
2
|
+
import { Command as A } from "commander";
|
|
3
|
+
import m from "inquirer";
|
|
4
|
+
import s from "fs";
|
|
5
|
+
import i from "path";
|
|
6
|
+
import { spawn as b } from "child_process";
|
|
7
|
+
const D = new A(), c = {
|
|
8
8
|
local: {
|
|
9
9
|
name: "Local (SQLite)",
|
|
10
10
|
description: "Local development setup with SQLite database - great for getting started",
|
|
11
11
|
templateDir: "local",
|
|
12
|
-
packageJson: (
|
|
13
|
-
name:
|
|
12
|
+
packageJson: (o) => ({
|
|
13
|
+
name: o,
|
|
14
14
|
version: "1.0.0",
|
|
15
15
|
type: "module",
|
|
16
16
|
scripts: {
|
|
@@ -42,21 +42,22 @@ const b = new x(), n = {
|
|
|
42
42
|
name: "Cloudflare Simple (Single Tenant)",
|
|
43
43
|
description: "Single-tenant Cloudflare Workers setup with D1 database",
|
|
44
44
|
templateDir: "cloudflare-simple",
|
|
45
|
-
packageJson: (
|
|
46
|
-
name:
|
|
45
|
+
packageJson: (o) => ({
|
|
46
|
+
name: o,
|
|
47
47
|
version: "1.0.0",
|
|
48
48
|
type: "module",
|
|
49
49
|
scripts: {
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
dev: "wrangler dev --port 3000 --local-protocol https",
|
|
53
|
-
deploy: "wrangler deploy",
|
|
50
|
+
"copy-assets": "node copy-assets.js",
|
|
51
|
+
dev: "npm run copy-assets && wrangler dev --port 3000 --local-protocol https",
|
|
52
|
+
"dev:remote": "npm run copy-assets && wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
|
|
53
|
+
deploy: "npm run copy-assets && wrangler deploy --config wrangler.local.toml",
|
|
54
54
|
"db:migrate:local": "wrangler d1 migrations apply AUTH_DB --local",
|
|
55
|
-
"db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote",
|
|
55
|
+
"db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote --config wrangler.local.toml",
|
|
56
56
|
migrate: "wrangler d1 migrations apply AUTH_DB --local",
|
|
57
57
|
"seed:local": "node seed-helper.js",
|
|
58
58
|
"seed:remote": "node seed-helper.js '' '' remote",
|
|
59
|
-
seed: "node seed-helper.js"
|
|
59
|
+
seed: "node seed-helper.js",
|
|
60
|
+
setup: "cp wrangler.toml wrangler.local.toml && cp .dev.vars.example .dev.vars && echo '✅ Created wrangler.local.toml and .dev.vars - update with your IDs'"
|
|
60
61
|
},
|
|
61
62
|
dependencies: {
|
|
62
63
|
"@authhero/drizzle": "latest",
|
|
@@ -82,21 +83,22 @@ const b = new x(), n = {
|
|
|
82
83
|
name: "Cloudflare Multi-Tenant (Production)",
|
|
83
84
|
description: "Production-grade multi-tenant setup with D1 database and tenant management",
|
|
84
85
|
templateDir: "cloudflare-multitenant",
|
|
85
|
-
packageJson: (
|
|
86
|
-
name:
|
|
86
|
+
packageJson: (o) => ({
|
|
87
|
+
name: o,
|
|
87
88
|
version: "1.0.0",
|
|
88
89
|
type: "module",
|
|
89
90
|
scripts: {
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
dev: "wrangler dev --port 3000 --local-protocol https",
|
|
93
|
-
deploy: "wrangler deploy",
|
|
91
|
+
"copy-assets": "node copy-assets.js",
|
|
92
|
+
dev: "npm run copy-assets && wrangler dev --port 3000 --local-protocol https",
|
|
93
|
+
"dev:remote": "npm run copy-assets && wrangler dev --port 3000 --local-protocol https --remote --config wrangler.local.toml",
|
|
94
|
+
deploy: "npm run copy-assets && wrangler deploy --config wrangler.local.toml",
|
|
94
95
|
"db:migrate:local": "wrangler d1 migrations apply AUTH_DB --local",
|
|
95
|
-
"db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote",
|
|
96
|
+
"db:migrate:remote": "wrangler d1 migrations apply AUTH_DB --remote --config wrangler.local.toml",
|
|
96
97
|
migrate: "wrangler d1 migrations apply AUTH_DB --local",
|
|
97
98
|
"seed:local": "node seed-helper.js",
|
|
98
99
|
"seed:remote": "node seed-helper.js '' '' remote",
|
|
99
|
-
seed: "node seed-helper.js"
|
|
100
|
+
seed: "node seed-helper.js",
|
|
101
|
+
setup: "cp wrangler.toml wrangler.local.toml && cp .dev.vars.example .dev.vars && echo '✅ Created wrangler.local.toml and .dev.vars - update with your IDs'"
|
|
100
102
|
},
|
|
101
103
|
dependencies: {
|
|
102
104
|
"@authhero/drizzle": "latest",
|
|
@@ -119,13 +121,13 @@ const b = new x(), n = {
|
|
|
119
121
|
seedFile: "seed.ts"
|
|
120
122
|
}
|
|
121
123
|
};
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
124
|
+
function j(o, e) {
|
|
125
|
+
s.readdirSync(o).forEach((n) => {
|
|
126
|
+
const a = i.join(o, n), t = i.join(e, n);
|
|
127
|
+
s.lstatSync(a).isDirectory() ? (s.mkdirSync(t, { recursive: !0 }), j(a, t)) : s.copyFileSync(a, t);
|
|
126
128
|
});
|
|
127
129
|
}
|
|
128
|
-
function
|
|
130
|
+
function I() {
|
|
129
131
|
return `import { SqliteDialect, Kysely } from "kysely";
|
|
130
132
|
import Database from "better-sqlite3";
|
|
131
133
|
import createAdapters from "@authhero/kysely-adapter";
|
|
@@ -159,44 +161,158 @@ async function main() {
|
|
|
159
161
|
main().catch(console.error);
|
|
160
162
|
`;
|
|
161
163
|
}
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
function x(o) {
|
|
165
|
+
const e = i.join(o, ".github", "workflows");
|
|
166
|
+
s.mkdirSync(e, { recursive: !0 });
|
|
167
|
+
const r = `name: Unit tests
|
|
168
|
+
|
|
169
|
+
on: push
|
|
170
|
+
|
|
171
|
+
jobs:
|
|
172
|
+
test:
|
|
173
|
+
runs-on: ubuntu-latest
|
|
174
|
+
steps:
|
|
175
|
+
- uses: actions/checkout@v4
|
|
176
|
+
|
|
177
|
+
- name: Setup Node.js
|
|
178
|
+
uses: actions/setup-node@v4
|
|
179
|
+
with:
|
|
180
|
+
node-version: "22"
|
|
181
|
+
cache: "npm"
|
|
182
|
+
|
|
183
|
+
- name: Install dependencies
|
|
184
|
+
run: npm ci
|
|
185
|
+
|
|
186
|
+
- run: npm run type-check
|
|
187
|
+
- run: npm test
|
|
188
|
+
`, n = `name: Deploy to Dev
|
|
189
|
+
|
|
190
|
+
on:
|
|
191
|
+
push:
|
|
192
|
+
branches:
|
|
193
|
+
- main
|
|
194
|
+
|
|
195
|
+
jobs:
|
|
196
|
+
release:
|
|
197
|
+
name: Release and Deploy
|
|
198
|
+
runs-on: ubuntu-latest
|
|
199
|
+
steps:
|
|
200
|
+
- name: Checkout
|
|
201
|
+
uses: actions/checkout@v4
|
|
202
|
+
with:
|
|
203
|
+
fetch-depth: 0
|
|
204
|
+
|
|
205
|
+
- name: Setup Node.js
|
|
206
|
+
uses: actions/setup-node@v4
|
|
207
|
+
with:
|
|
208
|
+
node-version: "22"
|
|
209
|
+
cache: "npm"
|
|
210
|
+
|
|
211
|
+
- name: Install dependencies
|
|
212
|
+
run: npm ci
|
|
213
|
+
|
|
214
|
+
- name: Release
|
|
215
|
+
env:
|
|
216
|
+
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
|
|
217
|
+
run: npx semantic-release
|
|
218
|
+
|
|
219
|
+
- name: Deploy to Cloudflare (Dev)
|
|
220
|
+
uses: cloudflare/wrangler-action@v3
|
|
221
|
+
with:
|
|
222
|
+
apiToken: \${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
223
|
+
command: deploy
|
|
224
|
+
`, a = `name: Deploy to Production
|
|
225
|
+
|
|
226
|
+
on:
|
|
227
|
+
release:
|
|
228
|
+
types: ["released"]
|
|
229
|
+
|
|
230
|
+
jobs:
|
|
231
|
+
deploy:
|
|
232
|
+
name: Deploy to Production
|
|
233
|
+
runs-on: ubuntu-latest
|
|
234
|
+
steps:
|
|
235
|
+
- name: Checkout
|
|
236
|
+
uses: actions/checkout@v4
|
|
237
|
+
|
|
238
|
+
- name: Setup Node.js
|
|
239
|
+
uses: actions/setup-node@v4
|
|
240
|
+
with:
|
|
241
|
+
node-version: "22"
|
|
242
|
+
cache: "npm"
|
|
243
|
+
|
|
244
|
+
- name: Install dependencies
|
|
245
|
+
run: npm ci
|
|
246
|
+
|
|
247
|
+
- name: Deploy to Cloudflare (Production)
|
|
248
|
+
uses: cloudflare/wrangler-action@v3
|
|
249
|
+
with:
|
|
250
|
+
apiToken: \${{ secrets.PROD_CLOUDFLARE_API_TOKEN }}
|
|
251
|
+
command: deploy --env production
|
|
252
|
+
`;
|
|
253
|
+
s.writeFileSync(i.join(e, "unit-tests.yml"), r), s.writeFileSync(i.join(e, "deploy-dev.yml"), n), s.writeFileSync(i.join(e, "release.yml"), a), console.log("\\n📦 GitHub CI workflows created!");
|
|
254
|
+
}
|
|
255
|
+
function C(o) {
|
|
256
|
+
const e = {
|
|
257
|
+
branches: ["main"],
|
|
258
|
+
plugins: [
|
|
259
|
+
"@semantic-release/commit-analyzer",
|
|
260
|
+
"@semantic-release/release-notes-generator",
|
|
261
|
+
"@semantic-release/github"
|
|
262
|
+
]
|
|
263
|
+
};
|
|
264
|
+
s.writeFileSync(
|
|
265
|
+
i.join(o, ".releaserc.json"),
|
|
266
|
+
JSON.stringify(e, null, 2)
|
|
267
|
+
);
|
|
268
|
+
const r = i.join(o, "package.json"), n = JSON.parse(s.readFileSync(r, "utf-8"));
|
|
269
|
+
n.devDependencies = {
|
|
270
|
+
...n.devDependencies,
|
|
271
|
+
"semantic-release": "^24.0.0"
|
|
272
|
+
}, n.scripts = {
|
|
273
|
+
...n.scripts,
|
|
274
|
+
test: 'echo "No tests yet"',
|
|
275
|
+
"type-check": "tsc --noEmit"
|
|
276
|
+
}, s.writeFileSync(r, JSON.stringify(n, null, 2));
|
|
277
|
+
}
|
|
278
|
+
function v(o, e) {
|
|
279
|
+
return new Promise((r, n) => {
|
|
280
|
+
const a = b(o, [], {
|
|
281
|
+
cwd: e,
|
|
166
282
|
shell: !0,
|
|
167
283
|
stdio: "inherit"
|
|
168
284
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}),
|
|
285
|
+
a.on("close", (t) => {
|
|
286
|
+
t === 0 ? r() : n(new Error(`Command failed with exit code ${t}`));
|
|
287
|
+
}), a.on("error", n);
|
|
172
288
|
});
|
|
173
289
|
}
|
|
174
|
-
function S(
|
|
175
|
-
return new Promise((
|
|
176
|
-
const
|
|
177
|
-
cwd:
|
|
290
|
+
function S(o, e, r) {
|
|
291
|
+
return new Promise((n, a) => {
|
|
292
|
+
const t = b(o, [], {
|
|
293
|
+
cwd: e,
|
|
178
294
|
shell: !0,
|
|
179
295
|
stdio: "inherit",
|
|
180
|
-
env: { ...process.env, ...
|
|
296
|
+
env: { ...process.env, ...r }
|
|
181
297
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}),
|
|
298
|
+
t.on("close", (f) => {
|
|
299
|
+
f === 0 ? n() : a(new Error(`Command failed with exit code ${f}`));
|
|
300
|
+
}), t.on("error", a);
|
|
185
301
|
});
|
|
186
302
|
}
|
|
187
|
-
|
|
303
|
+
D.version("1.0.0").description("Create a new AuthHero project").argument("[project-name]", "name of the project").option(
|
|
188
304
|
"-t, --template <type>",
|
|
189
305
|
"template type: local, cloudflare-simple, or cloudflare-multitenant"
|
|
190
306
|
).option("-e, --email <email>", "admin email address").option("-p, --password <password>", "admin password (min 8 characters)").option(
|
|
191
307
|
"--package-manager <pm>",
|
|
192
308
|
"package manager to use: npm, yarn, pnpm, or bun"
|
|
193
|
-
).option("--skip-install", "skip installing dependencies").option("--skip-migrate", "skip running database migrations").option("--skip-seed", "skip seeding the database").option("--skip-start", "skip starting the development server").option("--
|
|
194
|
-
const
|
|
309
|
+
).option("--skip-install", "skip installing dependencies").option("--skip-migrate", "skip running database migrations").option("--skip-seed", "skip seeding the database").option("--skip-start", "skip starting the development server").option("--github-ci", "include GitHub CI workflows with semantic versioning").option("-y, --yes", "skip all prompts and use defaults/provided options").action(async (o, e) => {
|
|
310
|
+
const r = e.yes === !0;
|
|
195
311
|
console.log(`
|
|
196
312
|
🔐 Welcome to AuthHero!
|
|
197
313
|
`);
|
|
198
|
-
let
|
|
199
|
-
|
|
314
|
+
let n = o;
|
|
315
|
+
n || (r ? (n = "auth-server", console.log(`Using default project name: ${n}`)) : n = (await m.prompt([
|
|
200
316
|
{
|
|
201
317
|
type: "input",
|
|
202
318
|
name: "projectName",
|
|
@@ -205,60 +321,76 @@ b.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
205
321
|
validate: (p) => p !== "" || "Project name cannot be empty"
|
|
206
322
|
}
|
|
207
323
|
])).projectName);
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
) || (console.error(`❌ Invalid template: ${
|
|
324
|
+
const a = i.join(process.cwd(), n);
|
|
325
|
+
s.existsSync(a) && (console.error(`❌ Project "${n}" already exists.`), process.exit(1));
|
|
326
|
+
let t;
|
|
327
|
+
e.template ? (["local", "cloudflare-simple", "cloudflare-multitenant"].includes(
|
|
328
|
+
e.template
|
|
329
|
+
) || (console.error(`❌ Invalid template: ${e.template}`), console.error(
|
|
214
330
|
"Valid options: local, cloudflare-simple, cloudflare-multitenant"
|
|
215
|
-
), process.exit(1)),
|
|
331
|
+
), process.exit(1)), t = e.template, console.log(`Using template: ${c[t].name}`)) : t = (await m.prompt([
|
|
216
332
|
{
|
|
217
333
|
type: "list",
|
|
218
334
|
name: "setupType",
|
|
219
335
|
message: "Select your setup type:",
|
|
220
336
|
choices: [
|
|
221
337
|
{
|
|
222
|
-
name: `${
|
|
223
|
-
${
|
|
338
|
+
name: `${c.local.name}
|
|
339
|
+
${c.local.description}`,
|
|
224
340
|
value: "local",
|
|
225
|
-
short:
|
|
341
|
+
short: c.local.name
|
|
226
342
|
},
|
|
227
343
|
{
|
|
228
|
-
name: `${
|
|
229
|
-
${
|
|
344
|
+
name: `${c["cloudflare-simple"].name}
|
|
345
|
+
${c["cloudflare-simple"].description}`,
|
|
230
346
|
value: "cloudflare-simple",
|
|
231
|
-
short:
|
|
347
|
+
short: c["cloudflare-simple"].name
|
|
232
348
|
},
|
|
233
349
|
{
|
|
234
|
-
name: `${
|
|
235
|
-
${
|
|
350
|
+
name: `${c["cloudflare-multitenant"].name}
|
|
351
|
+
${c["cloudflare-multitenant"].description}`,
|
|
236
352
|
value: "cloudflare-multitenant",
|
|
237
|
-
short:
|
|
353
|
+
short: c["cloudflare-multitenant"].name
|
|
238
354
|
}
|
|
239
355
|
]
|
|
240
356
|
}
|
|
241
357
|
])).setupType;
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
JSON.stringify(
|
|
358
|
+
const f = c[t];
|
|
359
|
+
s.mkdirSync(a, { recursive: !0 }), s.writeFileSync(
|
|
360
|
+
i.join(a, "package.json"),
|
|
361
|
+
JSON.stringify(f.packageJson(n), null, 2)
|
|
246
362
|
);
|
|
247
|
-
const k =
|
|
363
|
+
const k = i.join(
|
|
248
364
|
import.meta.url.replace("file://", "").replace("/create-authhero.js", ""),
|
|
249
|
-
|
|
365
|
+
f.templateDir
|
|
250
366
|
);
|
|
251
|
-
if (
|
|
252
|
-
const l =
|
|
253
|
-
|
|
367
|
+
if (s.existsSync(k) ? j(k, a) : (console.error(`❌ Template directory not found: ${k}`), process.exit(1)), t === "cloudflare-simple" || t === "cloudflare-multitenant") {
|
|
368
|
+
const l = i.join(a, "wrangler.toml"), p = i.join(a, "wrangler.local.toml");
|
|
369
|
+
s.existsSync(l) && s.copyFileSync(l, p);
|
|
370
|
+
const d = i.join(a, ".dev.vars.example"), u = i.join(a, ".dev.vars");
|
|
371
|
+
s.existsSync(d) && s.copyFileSync(d, u), console.log(
|
|
372
|
+
"📁 Created wrangler.local.toml and .dev.vars for local development"
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
let y = !1;
|
|
376
|
+
if ((t === "cloudflare-simple" || t === "cloudflare-multitenant") && (e.githubCi !== void 0 ? (y = e.githubCi, y && console.log("Including GitHub CI workflows with semantic versioning")) : r || (y = (await m.prompt([
|
|
377
|
+
{
|
|
378
|
+
type: "confirm",
|
|
379
|
+
name: "includeGithubCi",
|
|
380
|
+
message: "Would you like to include GitHub CI with semantic versioning?",
|
|
381
|
+
default: !1
|
|
382
|
+
}
|
|
383
|
+
])).includeGithubCi), y && (x(a), C(a))), t === "local") {
|
|
384
|
+
const l = I();
|
|
385
|
+
s.writeFileSync(i.join(a, "src/seed.ts"), l);
|
|
254
386
|
}
|
|
255
387
|
console.log(
|
|
256
388
|
`
|
|
257
|
-
✅ Project "${
|
|
389
|
+
✅ Project "${n}" has been created with ${f.name} setup!
|
|
258
390
|
`
|
|
259
391
|
);
|
|
260
392
|
let h;
|
|
261
|
-
if (
|
|
393
|
+
if (e.skipInstall ? h = !1 : r ? h = !0 : h = (await m.prompt([
|
|
262
394
|
{
|
|
263
395
|
type: "confirm",
|
|
264
396
|
name: "shouldInstall",
|
|
@@ -267,9 +399,9 @@ b.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
267
399
|
}
|
|
268
400
|
])).shouldInstall, h) {
|
|
269
401
|
let l;
|
|
270
|
-
|
|
271
|
-
`❌ Invalid package manager: ${
|
|
272
|
-
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)), l =
|
|
402
|
+
e.packageManager ? (["npm", "yarn", "pnpm", "bun"].includes(e.packageManager) || (console.error(
|
|
403
|
+
`❌ Invalid package manager: ${e.packageManager}`
|
|
404
|
+
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)), l = e.packageManager) : r ? l = "pnpm" : l = (await m.prompt([
|
|
273
405
|
{
|
|
274
406
|
type: "list",
|
|
275
407
|
name: "packageManager",
|
|
@@ -287,35 +419,13 @@ b.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
287
419
|
`);
|
|
288
420
|
try {
|
|
289
421
|
const p = l === "pnpm" ? "pnpm install --ignore-workspace" : `${l} install`;
|
|
290
|
-
await v(p,
|
|
422
|
+
if (await v(p, a), t === "local" && (console.log(`
|
|
291
423
|
🔧 Building native modules...
|
|
292
|
-
`), await v("npm rebuild better-sqlite3",
|
|
424
|
+
`), await v("npm rebuild better-sqlite3", a)), console.log(`
|
|
293
425
|
✅ Dependencies installed successfully!
|
|
294
|
-
`)
|
|
295
|
-
let y = a.remote ? "remote" : "local";
|
|
296
|
-
if (e === "local" || e === "cloudflare-simple" || e === "cloudflare-multitenant") {
|
|
297
|
-
(e === "cloudflare-simple" || e === "cloudflare-multitenant") && !s && !a.remote && (y = (await c.prompt([
|
|
298
|
-
{
|
|
299
|
-
type: "list",
|
|
300
|
-
name: "mode",
|
|
301
|
-
message: "Would you like to run in local mode or remote mode?",
|
|
302
|
-
choices: [
|
|
303
|
-
{
|
|
304
|
-
name: "Local (using local D1 database)",
|
|
305
|
-
value: "local",
|
|
306
|
-
short: "Local"
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
name: "Remote (using production D1 database)",
|
|
310
|
-
value: "remote",
|
|
311
|
-
short: "Remote"
|
|
312
|
-
}
|
|
313
|
-
],
|
|
314
|
-
default: "local"
|
|
315
|
-
}
|
|
316
|
-
])).mode);
|
|
426
|
+
`), t === "local" || t === "cloudflare-simple" || t === "cloudflare-multitenant") {
|
|
317
427
|
let u;
|
|
318
|
-
if (
|
|
428
|
+
if (e.skipMigrate && e.skipSeed ? u = !1 : r ? u = !e.skipMigrate || !e.skipSeed : u = (await m.prompt([
|
|
319
429
|
{
|
|
320
430
|
type: "confirm",
|
|
321
431
|
name: "shouldSetup",
|
|
@@ -323,73 +433,61 @@ b.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
323
433
|
default: !0
|
|
324
434
|
}
|
|
325
435
|
])).shouldSetup, u) {
|
|
326
|
-
let
|
|
327
|
-
|
|
328
|
-
username:
|
|
329
|
-
password:
|
|
330
|
-
}, console.log(`Using admin email: ${
|
|
436
|
+
let g;
|
|
437
|
+
e.email && e.password ? (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.email) || (console.error("❌ Invalid email address provided"), process.exit(1)), e.password.length < 8 && (console.error("❌ Password must be at least 8 characters"), process.exit(1)), g = {
|
|
438
|
+
username: e.email,
|
|
439
|
+
password: e.password
|
|
440
|
+
}, console.log(`Using admin email: ${e.email}`)) : g = await m.prompt([
|
|
331
441
|
{
|
|
332
442
|
type: "input",
|
|
333
443
|
name: "username",
|
|
334
444
|
message: "Admin email:",
|
|
335
445
|
default: "admin@example.com",
|
|
336
|
-
validate: (
|
|
446
|
+
validate: (w) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(w) || "Please enter a valid email address"
|
|
337
447
|
},
|
|
338
448
|
{
|
|
339
449
|
type: "password",
|
|
340
450
|
name: "password",
|
|
341
451
|
message: "Admin password:",
|
|
342
452
|
mask: "*",
|
|
343
|
-
validate: (
|
|
453
|
+
validate: (w) => w.length < 8 ? "Password must be at least 8 characters" : !0
|
|
344
454
|
}
|
|
345
|
-
]),
|
|
346
|
-
console.log(`
|
|
455
|
+
]), e.skipMigrate || (console.log(`
|
|
347
456
|
🔄 Running migrations...
|
|
348
|
-
`)
|
|
349
|
-
const m = (e === "cloudflare-simple" || e === "cloudflare-multitenant") && y === "remote" ? `${l} run db:migrate:remote` : `${l} run migrate`;
|
|
350
|
-
await v(m, t);
|
|
351
|
-
}
|
|
352
|
-
if (!a.skipSeed)
|
|
353
|
-
if (console.log(`
|
|
457
|
+
`), await v(`${l} run migrate`, a)), e.skipSeed || (console.log(`
|
|
354
458
|
🌱 Seeding database...
|
|
355
|
-
`),
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
ADMIN_PASSWORD: d.password
|
|
362
|
-
}
|
|
363
|
-
);
|
|
364
|
-
else {
|
|
365
|
-
const m = y === "remote" ? `${l} run seed:remote` : `${l} run seed:local`;
|
|
366
|
-
await S(m, t, {
|
|
367
|
-
ADMIN_EMAIL: d.username,
|
|
368
|
-
ADMIN_PASSWORD: d.password
|
|
369
|
-
});
|
|
459
|
+
`), t === "local" ? await S(
|
|
460
|
+
`${l} run seed`,
|
|
461
|
+
a,
|
|
462
|
+
{
|
|
463
|
+
ADMIN_EMAIL: g.username,
|
|
464
|
+
ADMIN_PASSWORD: g.password
|
|
370
465
|
}
|
|
466
|
+
) : await S(
|
|
467
|
+
`${l} run seed:local`,
|
|
468
|
+
a,
|
|
469
|
+
{
|
|
470
|
+
ADMIN_EMAIL: g.username,
|
|
471
|
+
ADMIN_PASSWORD: g.password
|
|
472
|
+
}
|
|
473
|
+
));
|
|
371
474
|
}
|
|
372
475
|
}
|
|
373
|
-
let
|
|
374
|
-
|
|
476
|
+
let d;
|
|
477
|
+
e.skipStart || r ? d = !1 : d = (await m.prompt([
|
|
375
478
|
{
|
|
376
479
|
type: "confirm",
|
|
377
480
|
name: "shouldStart",
|
|
378
481
|
message: "Would you like to start the development server?",
|
|
379
482
|
default: !0
|
|
380
483
|
}
|
|
381
|
-
])).shouldStart,
|
|
382
|
-
|
|
383
|
-
`
|
|
484
|
+
])).shouldStart, d && (console.log(
|
|
485
|
+
`
|
|
384
486
|
🚀 Starting development server on https://localhost:3000 ...
|
|
385
487
|
`
|
|
386
|
-
|
|
387
|
-
const u = (e === "cloudflare-simple" || e === "cloudflare-multitenant") && y === "remote" ? `${l} run dev:remote` : `${l} run dev`;
|
|
388
|
-
await v(u, t);
|
|
389
|
-
}
|
|
390
|
-
s && !w && (console.log(`
|
|
488
|
+
), await v(`${l} run dev`, a)), r && !d && (console.log(`
|
|
391
489
|
✅ Setup complete!`), console.log(`
|
|
392
|
-
To start the development server:`), console.log(` cd ${
|
|
490
|
+
To start the development server:`), console.log(` cd ${n}`), console.log(" npm run dev"), (t === "cloudflare-simple" || t === "cloudflare-multitenant") && console.log(
|
|
393
491
|
`
|
|
394
492
|
Server will be available at: https://localhost:3000`
|
|
395
493
|
));
|
|
@@ -398,9 +496,9 @@ Server will be available at: https://localhost:3000`
|
|
|
398
496
|
❌ An error occurred:`, p), process.exit(1);
|
|
399
497
|
}
|
|
400
498
|
}
|
|
401
|
-
h || (console.log("Next steps:"), console.log(` cd ${
|
|
499
|
+
h || (console.log("Next steps:"), console.log(` cd ${n}`), t === "local" ? (console.log(" npm install"), console.log(" npm run migrate"), console.log(
|
|
402
500
|
" ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed"
|
|
403
|
-
), console.log(" npm run dev")) : (
|
|
501
|
+
), console.log(" npm run dev")) : (t === "cloudflare-simple" || t === "cloudflare-multitenant") && (console.log(" npm install"), console.log(
|
|
404
502
|
" npm run migrate # or npm run db:migrate:remote for production"
|
|
405
503
|
), console.log(
|
|
406
504
|
" ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=yourpassword npm run seed"
|
|
@@ -409,4 +507,4 @@ Server will be available at: https://localhost:3000`)), console.log(`
|
|
|
409
507
|
For more information, visit: https://authhero.net/docs
|
|
410
508
|
`));
|
|
411
509
|
});
|
|
412
|
-
|
|
510
|
+
D.parse(process.argv);
|
package/dist/local/src/app.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Context } from "hono";
|
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
3
|
import { AuthHeroConfig, init } from "authhero";
|
|
4
4
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
5
|
+
import { serveStatic } from "@hono/node-server/serve-static";
|
|
5
6
|
|
|
6
7
|
export default function createApp(config: AuthHeroConfig) {
|
|
7
8
|
const { app } = init(config);
|
|
@@ -20,7 +21,15 @@ export default function createApp(config: AuthHeroConfig) {
|
|
|
20
21
|
status: "running",
|
|
21
22
|
});
|
|
22
23
|
})
|
|
23
|
-
.get("/docs", swaggerUI({ url: "/api/v2/spec" }))
|
|
24
|
+
.get("/docs", swaggerUI({ url: "/api/v2/spec" }))
|
|
25
|
+
// Serve static assets (widget, CSS, JS) from authhero package
|
|
26
|
+
.get(
|
|
27
|
+
"/u/*",
|
|
28
|
+
serveStatic({
|
|
29
|
+
root: "./node_modules/authhero/dist/assets/u",
|
|
30
|
+
rewriteRequestPath: (path) => path.replace("/u", ""),
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
24
33
|
|
|
25
34
|
return app;
|
|
26
35
|
}
|