@authhero/multi-tenancy 1.0.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/LICENSE +21 -0
- package/README.md +87 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 authhero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @authhero/multi-tenancy
|
|
2
|
+
|
|
3
|
+
Multi-tenancy support for AuthHero with organization-based access control, per-tenant database isolation, and subdomain routing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 **Organization-based Access Control** - Control tenant access via JWT tokens with `org_id` claims
|
|
8
|
+
- 💾 **Database Isolation** - Per-tenant databases with D1, Turso, or custom providers
|
|
9
|
+
- ⚙️ **Settings Inheritance** - Inherit configuration from main tenant to child tenants
|
|
10
|
+
- 🌐 **Subdomain Routing** - Automatic subdomain-to-tenant resolution
|
|
11
|
+
- 🔄 **Tenant Lifecycle** - Automated provisioning and deprovisioning
|
|
12
|
+
- 🪝 **Hooks Integration** - Seamless integration with AuthHero hooks system
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @authhero/multi-tenancy
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
📚 **Full documentation**: [https://authhero.net/packages/multi-tenancy/](https://authhero.net/packages/multi-tenancy/)
|
|
23
|
+
|
|
24
|
+
- [Architecture](https://authhero.net/packages/multi-tenancy/architecture) - Organization-tenant model and token-based access
|
|
25
|
+
- [Database Isolation](https://authhero.net/packages/multi-tenancy/database-isolation) - Per-tenant databases
|
|
26
|
+
- [API Reference](https://authhero.net/packages/multi-tenancy/api-reference) - Complete API documentation
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Hono } from "hono";
|
|
32
|
+
import { createAuthhero } from "authhero";
|
|
33
|
+
import { setupMultiTenancy } from "@authhero/multi-tenancy";
|
|
34
|
+
|
|
35
|
+
const multiTenancy = setupMultiTenancy({
|
|
36
|
+
accessControl: {
|
|
37
|
+
mainTenantId: "main",
|
|
38
|
+
defaultPermissions: ["tenant:admin"],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const app = new Hono();
|
|
43
|
+
|
|
44
|
+
// Apply middleware
|
|
45
|
+
app.use("*", multiTenancy.middleware);
|
|
46
|
+
|
|
47
|
+
// Mount management routes
|
|
48
|
+
app.route("/management", multiTenancy.app);
|
|
49
|
+
|
|
50
|
+
// Mount AuthHero with hooks
|
|
51
|
+
app.route(
|
|
52
|
+
"/",
|
|
53
|
+
createAuthhero({
|
|
54
|
+
dataAdapter: env.data,
|
|
55
|
+
hooks: multiTenancy.hooks,
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Key Concepts
|
|
61
|
+
|
|
62
|
+
### Organization-Tenant Model
|
|
63
|
+
|
|
64
|
+
Organizations on a "main" tenant represent and control access to child tenants. Each organization maps to one child tenant.
|
|
65
|
+
|
|
66
|
+
### Token-Based Access
|
|
67
|
+
|
|
68
|
+
Access is controlled via the `org_id` claim in JWT tokens:
|
|
69
|
+
|
|
70
|
+
- **No `org_id`**: Main tenant only
|
|
71
|
+
- **With `org_id`**: Access to matching tenant
|
|
72
|
+
|
|
73
|
+
### Silent Authentication
|
|
74
|
+
|
|
75
|
+
Switch tenants by requesting a new token with a different organization:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const token = await getAccessTokenSilently({
|
|
79
|
+
authorizationParams: {
|
|
80
|
+
organization: "tenant-id",
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@authhero/multi-tenancy",
|
|
3
|
+
"private": false,
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org/",
|
|
7
|
+
"tag": "latest"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://authhero.net",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
|
+
},
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"description": "Multi-tenancy support for AuthHero with organization-based access control and per-tenant database isolation",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "dist/multi-tenancy.cjs",
|
|
20
|
+
"module": "dist/multi-tenancy.mjs",
|
|
21
|
+
"types": "dist/multi-tenancy.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/multi-tenancy.d.ts",
|
|
25
|
+
"require": "./dist/multi-tenancy.cjs",
|
|
26
|
+
"import": "./dist/multi-tenancy.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@hono/zod-openapi": "^0.19.10",
|
|
31
|
+
"@types/better-sqlite3": "^7.6.12",
|
|
32
|
+
"@types/node": "^22.0.0",
|
|
33
|
+
"better-sqlite3": "^11.7.0",
|
|
34
|
+
"dts-bundle-generator": "^9.5.1",
|
|
35
|
+
"hono": "^4.7.0",
|
|
36
|
+
"kysely": "^0.27.4",
|
|
37
|
+
"typescript": "^5.6.0",
|
|
38
|
+
"vite": "^6.0.0",
|
|
39
|
+
"vitest": "^2.1.0",
|
|
40
|
+
"@authhero/kysely-adapter": "10.59.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"zod": "^3.24.0",
|
|
44
|
+
"@authhero/adapter-interfaces": "0.101.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@hono/zod-openapi": "^0.19.10",
|
|
48
|
+
"hono": "^4.7.0",
|
|
49
|
+
"authhero": "1.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|