@authhero/multi-tenancy 13.17.0 → 13.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.
Files changed (2) hide show
  1. package/README.md +59 -24
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -9,15 +9,19 @@ Multi-tenancy support for AuthHero with organization-based access control, per-t
9
9
  - ⚙️ **Settings Inheritance** - Inherit configuration from main tenant to child tenants
10
10
  - 🌐 **Subdomain Routing** - Automatic subdomain-to-tenant resolution
11
11
  - 🔄 **Tenant Lifecycle** - Automated provisioning and deprovisioning
12
- - 🪝 **Hooks Integration** - Seamless integration with AuthHero hooks system
13
- - 📡 **Resource Server Sync** - Automatically sync resource servers from main tenant to all child tenants
12
+ - 🪝 **Composable Architecture** - Combine multi-tenancy features with the base AuthHero package
13
+ - 📡 **Entity Sync** - Automatically sync resource servers, roles, and connections from control plane to all child tenants
14
14
 
15
15
  ## Installation
16
16
 
17
17
  ```bash
18
- pnpm add @authhero/multi-tenancy
18
+ pnpm add authhero @authhero/multi-tenancy
19
19
  ```
20
20
 
21
+ ::: tip Peer Dependency
22
+ `@authhero/multi-tenancy` requires `authhero` as a peer dependency. Both packages must be installed.
23
+ :::
24
+
21
25
  ## Documentation
22
26
 
23
27
  📚 **Full documentation**: [https://authhero.net/packages/multi-tenancy/](https://authhero.net/packages/multi-tenancy/)
@@ -29,33 +33,64 @@ pnpm add @authhero/multi-tenancy
29
33
  ## Quick Start
30
34
 
31
35
  ```typescript
32
- import { Hono } from "hono";
33
- import { createAuthhero } from "authhero";
34
- import { setupMultiTenancy } from "@authhero/multi-tenancy";
35
-
36
- const multiTenancy = setupMultiTenancy({
37
- accessControl: {
38
- controlPlaneTenantId: "control_plane",
39
- defaultPermissions: ["tenant:admin"],
36
+ import { init, AuthHeroConfig, fetchAll } from "authhero";
37
+ import {
38
+ createSyncHooks,
39
+ createTenantsOpenAPIRouter,
40
+ createProtectSyncedMiddleware,
41
+ } from "@authhero/multi-tenancy";
42
+ import createAdapters from "@authhero/kysely-adapter";
43
+
44
+ const CONTROL_PLANE_TENANT_ID = "control_plane";
45
+ const dataAdapter = createAdapters(db);
46
+
47
+ // Create sync hooks for syncing entities from control plane to child tenants
48
+ const { entityHooks, tenantHooks } = createSyncHooks({
49
+ controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
50
+ getChildTenantIds: async () => {
51
+ const allTenants = await fetchAll(
52
+ (params) => dataAdapter.tenants.list(params),
53
+ "tenants",
54
+ { cursorField: "id", pageSize: 100 }
55
+ );
56
+ return allTenants
57
+ .filter((t) => t.id !== CONTROL_PLANE_TENANT_ID)
58
+ .map((t) => t.id);
59
+ },
60
+ getAdapters: async () => dataAdapter,
61
+ getControlPlaneAdapters: async () => dataAdapter,
62
+ sync: {
63
+ resourceServers: true,
64
+ roles: true,
65
+ connections: true,
40
66
  },
41
67
  });
42
68
 
43
- const app = new Hono();
69
+ // Create tenants router
70
+ const tenantsRouter = createTenantsOpenAPIRouter(
71
+ {
72
+ accessControl: {
73
+ controlPlaneTenantId: CONTROL_PLANE_TENANT_ID,
74
+ requireOrganizationMatch: false,
75
+ defaultPermissions: ["tenant:admin"],
76
+ },
77
+ },
78
+ { tenants: tenantHooks }
79
+ );
44
80
 
45
- // Apply middleware
46
- app.use("*", multiTenancy.middleware);
81
+ // Initialize AuthHero with sync hooks and tenant routes
82
+ const { app } = init({
83
+ dataAdapter,
84
+ entityHooks,
85
+ managementApiExtensions: [
86
+ { path: "/tenants", router: tenantsRouter },
87
+ ],
88
+ });
47
89
 
48
- // Mount management routes
49
- app.route("/management", multiTenancy.app);
90
+ // Add middleware to protect synced entities
91
+ app.use("/api/v2/*", createProtectSyncedMiddleware());
50
92
 
51
- // Mount AuthHero with hooks
52
- app.route(
53
- "/",
54
- createAuthhero({
55
- dataAdapter: env.data,
56
- hooks: multiTenancy.hooks,
57
- }),
58
- );
93
+ export default app;
59
94
  ```
60
95
 
61
96
  ## Key Concepts
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "13.17.0",
14
+ "version": "13.18.0",
15
15
  "description": "Multi-tenancy support for AuthHero with organization-based access control and per-tenant database isolation",
16
16
  "files": [
17
17
  "dist"