create-authhero 0.7.0 → 0.8.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/dist/cloudflare-simple/README.md +109 -10
- package/dist/cloudflare-simple/drizzle.config.ts +8 -0
- package/dist/cloudflare-simple/migrations/0000_init.sql +782 -0
- package/dist/cloudflare-simple/migrations/meta/0000_snapshot.json +5325 -0
- package/dist/cloudflare-simple/migrations/meta/_journal.json +13 -0
- package/dist/cloudflare-simple/seed-helper.js +75 -0
- package/dist/cloudflare-simple/src/app.ts +10 -0
- package/dist/cloudflare-simple/src/db/schema.ts +845 -0
- package/dist/cloudflare-simple/src/index.ts +32 -14
- package/dist/cloudflare-simple/src/seed.ts +64 -0
- package/dist/cloudflare-simple/wrangler.toml +2 -0
- package/dist/create-authhero.js +177 -98
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper script to seed the Cloudflare D1 database
|
|
5
|
+
* This script starts the seed worker, makes a request to it, and then stops it
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn } from "child_process";
|
|
9
|
+
import { setTimeout } from "timers/promises";
|
|
10
|
+
|
|
11
|
+
const adminEmail = process.argv[2] || process.env.ADMIN_EMAIL;
|
|
12
|
+
const adminPassword = process.argv[3] || process.env.ADMIN_PASSWORD;
|
|
13
|
+
const mode = process.argv[4] || "local";
|
|
14
|
+
|
|
15
|
+
if (!adminEmail || !adminPassword) {
|
|
16
|
+
console.error("Usage: node seed-helper.js <email> <password> [local|remote]");
|
|
17
|
+
console.error(
|
|
18
|
+
" or: ADMIN_EMAIL=... ADMIN_PASSWORD=... node seed-helper.js",
|
|
19
|
+
);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
console.log(`Starting seed worker in ${mode} mode...`);
|
|
24
|
+
|
|
25
|
+
const wranglerArgs = ["dev", "src/seed.ts"];
|
|
26
|
+
if (mode === "remote") {
|
|
27
|
+
wranglerArgs.push("--remote");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const worker = spawn("wrangler", wranglerArgs, {
|
|
31
|
+
stdio: ["inherit", "pipe", "inherit"],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let workerUrl = "http://localhost:8787";
|
|
35
|
+
|
|
36
|
+
// Listen for the worker output to get the URL
|
|
37
|
+
worker.stdout?.on("data", (data) => {
|
|
38
|
+
const output = data.toString();
|
|
39
|
+
process.stdout.write(output);
|
|
40
|
+
|
|
41
|
+
// Look for the URL in the output
|
|
42
|
+
const urlMatch = output.match(/http:\/\/[^\s]+/);
|
|
43
|
+
if (urlMatch) {
|
|
44
|
+
workerUrl = urlMatch[0].replace(/\/$/, ""); // Remove trailing slash
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Wait for the worker to start
|
|
49
|
+
await setTimeout(3000);
|
|
50
|
+
|
|
51
|
+
console.log(`\nMaking seed request to ${workerUrl}...`);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const url = `${workerUrl}/?email=${encodeURIComponent(adminEmail)}&password=${encodeURIComponent(adminPassword)}`;
|
|
55
|
+
|
|
56
|
+
const response = await fetch(url);
|
|
57
|
+
const result = await response.json();
|
|
58
|
+
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
console.log("\n✅ Seed completed successfully!");
|
|
61
|
+
console.log(JSON.stringify(result, null, 2));
|
|
62
|
+
} else {
|
|
63
|
+
console.error("\n❌ Seed failed:");
|
|
64
|
+
console.error(JSON.stringify(result, null, 2));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("\n❌ Failed to connect to seed worker:");
|
|
69
|
+
console.error(error);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
} finally {
|
|
72
|
+
// Stop the worker
|
|
73
|
+
console.log("\nStopping seed worker...");
|
|
74
|
+
worker.kill();
|
|
75
|
+
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
|
+
import { cors } from "hono/cors";
|
|
3
4
|
import { AuthHeroConfig, init } from "authhero";
|
|
4
5
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
5
6
|
|
|
6
7
|
export default function createApp(config: AuthHeroConfig) {
|
|
7
8
|
const { app } = init(config);
|
|
8
9
|
|
|
10
|
+
// Enable CORS for all origins in development
|
|
11
|
+
app.use("*", cors({
|
|
12
|
+
origin: (origin) => origin || "*",
|
|
13
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
14
|
+
allowHeaders: ["Content-Type", "Authorization", "Auth0-Client"],
|
|
15
|
+
exposeHeaders: ["Content-Length"],
|
|
16
|
+
credentials: true,
|
|
17
|
+
}));
|
|
18
|
+
|
|
9
19
|
app
|
|
10
20
|
.onError((err, ctx) => {
|
|
11
21
|
if (err instanceof HTTPException) {
|