create-authhero 0.11.0 → 0.13.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-multitenant/migrations/0001_add_synced_column.sql +8 -0
- package/dist/cloudflare-multitenant/src/app.ts +12 -46
- package/dist/cloudflare-multitenant/src/index.ts +1 -1
- package/dist/cloudflare-multitenant/src/seed.ts +4 -1
- package/dist/cloudflare-simple/migrations/0001_add_synced_column.sql +8 -0
- package/dist/cloudflare-simple/src/seed.ts +3 -0
- package/dist/create-authhero.js +3 -4
- package/dist/local/migrations/0001_add_synced_column.sql +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Add synced column to resource_servers table
|
|
2
|
+
ALTER TABLE `resource_servers` ADD COLUMN `synced` integer;
|
|
3
|
+
--> statement-breakpoint
|
|
4
|
+
-- Add synced column to roles table
|
|
5
|
+
ALTER TABLE `roles` ADD COLUMN `synced` integer;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
-- Add synced column to connections table
|
|
8
|
+
ALTER TABLE `connections` ADD COLUMN `synced` integer;
|
|
@@ -1,61 +1,27 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
|
-
import { AuthHeroConfig, init } from "authhero";
|
|
4
3
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
init,
|
|
6
|
+
MultiTenantAuthHeroConfig,
|
|
7
|
+
DataAdapters,
|
|
9
8
|
} from "@authhero/multi-tenancy";
|
|
10
9
|
|
|
11
10
|
// Main tenant ID - the tenant that manages all other tenants
|
|
12
11
|
const MAIN_TENANT_ID = "main";
|
|
13
12
|
|
|
14
|
-
export default function createApp(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
defaultPermissions: ["tenant:admin"],
|
|
21
|
-
},
|
|
22
|
-
settingsInheritance: {
|
|
23
|
-
inheritFromMain: true,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Resource server sync hooks (syncs from main tenant to child tenants)
|
|
28
|
-
const resourceServerHooks = createResourceServerSyncHooks({
|
|
29
|
-
mainTenantId: MAIN_TENANT_ID,
|
|
30
|
-
getChildTenantIds: async () => {
|
|
31
|
-
const result = await config.dataAdapter.tenants.list({ per_page: 100 });
|
|
32
|
-
return result.tenants
|
|
33
|
-
.filter((t) => t.id !== MAIN_TENANT_ID)
|
|
34
|
-
.map((t) => t.id);
|
|
35
|
-
},
|
|
36
|
-
getAdapters: async () => config.dataAdapter,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Tenant creation hooks (copies resource servers to new tenants)
|
|
40
|
-
const tenantResourceServerSync = createTenantResourceServerSyncHooks({
|
|
41
|
-
mainTenantId: MAIN_TENANT_ID,
|
|
42
|
-
getMainTenantAdapters: async () => config.dataAdapter,
|
|
43
|
-
getAdapters: async () => config.dataAdapter,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const { app, managementApp } = init({
|
|
13
|
+
export default function createApp(
|
|
14
|
+
config: Omit<MultiTenantAuthHeroConfig, "mainTenantId"> & {
|
|
15
|
+
dataAdapter: DataAdapters;
|
|
16
|
+
},
|
|
17
|
+
) {
|
|
18
|
+
const { app } = init({
|
|
47
19
|
...config,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tenants: tenantResourceServerSync,
|
|
52
|
-
},
|
|
20
|
+
mainTenantId: MAIN_TENANT_ID,
|
|
21
|
+
// Sync resource servers from main tenant to all child tenants
|
|
22
|
+
syncResourceServers: true,
|
|
53
23
|
});
|
|
54
24
|
|
|
55
|
-
// Mount multi-tenancy tenant management routes (list, create, update, delete)
|
|
56
|
-
// Routes are available at /api/v2/tenants
|
|
57
|
-
managementApp.route("", multiTenancy.app);
|
|
58
|
-
|
|
59
25
|
app
|
|
60
26
|
.onError((err, ctx) => {
|
|
61
27
|
if (err instanceof HTTPException) {
|
|
@@ -3,7 +3,7 @@ import { Kysely } from "kysely";
|
|
|
3
3
|
import createAdapters from "@authhero/kysely-adapter";
|
|
4
4
|
import createApp from "./app";
|
|
5
5
|
import { Env } from "./types";
|
|
6
|
-
import { AuthHeroConfig } from "authhero";
|
|
6
|
+
import { AuthHeroConfig } from "@authhero/multi-tenancy";
|
|
7
7
|
|
|
8
8
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
9
9
|
// OPTIONAL: Uncomment to enable Cloudflare adapters (Analytics Engine, etc.)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { D1Dialect } from "kysely-d1";
|
|
2
2
|
import { Kysely } from "kysely";
|
|
3
3
|
import createAdapters from "@authhero/kysely-adapter";
|
|
4
|
-
import { seed } from "authhero";
|
|
4
|
+
import { seed } from "@authhero/multi-tenancy";
|
|
5
5
|
|
|
6
6
|
interface Env {
|
|
7
7
|
AUTH_DB: D1Database;
|
|
@@ -12,6 +12,8 @@ export default {
|
|
|
12
12
|
const url = new URL(request.url);
|
|
13
13
|
const adminEmail = url.searchParams.get("email");
|
|
14
14
|
const adminPassword = url.searchParams.get("password");
|
|
15
|
+
// Compute issuer from the request URL (for Management API identifier)
|
|
16
|
+
const issuer = `${url.protocol}//${url.host}/`;
|
|
15
17
|
|
|
16
18
|
if (!adminEmail || !adminPassword) {
|
|
17
19
|
return new Response(
|
|
@@ -34,6 +36,7 @@ export default {
|
|
|
34
36
|
const result = await seed(adapters, {
|
|
35
37
|
adminEmail,
|
|
36
38
|
adminPassword,
|
|
39
|
+
issuer,
|
|
37
40
|
});
|
|
38
41
|
|
|
39
42
|
return new Response(
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Add synced column to resource_servers table
|
|
2
|
+
ALTER TABLE `resource_servers` ADD COLUMN `synced` integer;
|
|
3
|
+
--> statement-breakpoint
|
|
4
|
+
-- Add synced column to roles table
|
|
5
|
+
ALTER TABLE `roles` ADD COLUMN `synced` integer;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
-- Add synced column to connections table
|
|
8
|
+
ALTER TABLE `connections` ADD COLUMN `synced` integer;
|
|
@@ -12,6 +12,8 @@ export default {
|
|
|
12
12
|
const url = new URL(request.url);
|
|
13
13
|
const adminEmail = url.searchParams.get("email");
|
|
14
14
|
const adminPassword = url.searchParams.get("password");
|
|
15
|
+
// Compute issuer from the request URL (for Management API identifier)
|
|
16
|
+
const issuer = `${url.protocol}//${url.host}/`;
|
|
15
17
|
|
|
16
18
|
if (!adminEmail || !adminPassword) {
|
|
17
19
|
return new Response(
|
|
@@ -34,6 +36,7 @@ export default {
|
|
|
34
36
|
const result = await seed(adapters, {
|
|
35
37
|
adminEmail,
|
|
36
38
|
adminPassword,
|
|
39
|
+
issuer,
|
|
37
40
|
});
|
|
38
41
|
|
|
39
42
|
return new Response(
|
package/dist/create-authhero.js
CHANGED
|
@@ -104,7 +104,6 @@ const D = new x(), n = {
|
|
|
104
104
|
"@authhero/multi-tenancy": "latest",
|
|
105
105
|
"@hono/swagger-ui": "^0.5.0",
|
|
106
106
|
"@hono/zod-openapi": "^0.19.0",
|
|
107
|
-
authhero: "latest",
|
|
108
107
|
hono: "^4.6.0",
|
|
109
108
|
kysely: "latest",
|
|
110
109
|
"kysely-d1": "latest"
|
|
@@ -270,18 +269,18 @@ D.version("1.0.0").description("Create a new AuthHero project").argument("[proje
|
|
|
270
269
|
let l;
|
|
271
270
|
a.packageManager ? (["npm", "yarn", "pnpm", "bun"].includes(a.packageManager) || (console.error(
|
|
272
271
|
`❌ Invalid package manager: ${a.packageManager}`
|
|
273
|
-
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)), l = a.packageManager) : s ? l = "
|
|
272
|
+
), console.error("Valid options: npm, yarn, pnpm, bun"), process.exit(1)), l = a.packageManager) : s ? l = "pnpm" : l = (await c.prompt([
|
|
274
273
|
{
|
|
275
274
|
type: "list",
|
|
276
275
|
name: "packageManager",
|
|
277
276
|
message: "Which package manager would you like to use?",
|
|
278
277
|
choices: [
|
|
278
|
+
{ name: "pnpm", value: "pnpm" },
|
|
279
279
|
{ name: "npm", value: "npm" },
|
|
280
280
|
{ name: "yarn", value: "yarn" },
|
|
281
|
-
{ name: "pnpm", value: "pnpm" },
|
|
282
281
|
{ name: "bun", value: "bun" }
|
|
283
282
|
],
|
|
284
|
-
default: "
|
|
283
|
+
default: "pnpm"
|
|
285
284
|
}
|
|
286
285
|
])).packageManager, console.log(`
|
|
287
286
|
📦 Installing dependencies with ${l}...
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Add synced column to resource_servers table
|
|
2
|
+
ALTER TABLE `resource_servers` ADD COLUMN `synced` integer;
|
|
3
|
+
--> statement-breakpoint
|
|
4
|
+
-- Add synced column to roles table
|
|
5
|
+
ALTER TABLE `roles` ADD COLUMN `synced` integer;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
-- Add synced column to connections table
|
|
8
|
+
ALTER TABLE `connections` ADD COLUMN `synced` integer;
|