@xeplr/auth 1.1.7 → 1.1.8

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 CHANGED
@@ -537,7 +537,7 @@ These are migration defaults; the Access Matrix changes them.
537
537
 
538
538
  `userTenantsMapping` records membership: `userId`, `level` (`l1`–`l4`, matching `mtId1`–`mtId4`), `value` (the app's own id at that level — auth owns no tenant tree), an optional `roleId`, `isActive`. One row per user, level and value.
539
539
 
540
- `@xeplr/db`'s `mtMiddleware` trusts whatever tenant header it is given. `mtMembershipMiddleware` is what checks it: for each configured slot whose header is present, the caller needs an active membership row with that value, or gets `403 Not authorized for <slot> "<value>"`. An absent header is left alone. It does nothing when multi-tenancy is not enabled.
540
+ `@xeplr/db`'s `mtMiddleware` trusts whatever tenant header it is given. `mtMembershipMiddleware` is what checks it: for each configured slot whose header is present, the caller needs an active membership row with that value, or gets `403 Not authorized for <slot> "<value>"`. An absent header is left alone. It does nothing when multi-tenancy is not enabled. **Super Admin passes whatever the headers say**: the role runs the whole install, so it goes into every company and workspace without a membership row.
541
541
 
542
542
  ### Roles belong to a company
543
543
 
@@ -1,5 +1,6 @@
1
1
  const { getMtConfig } = require('@xeplr/db');
2
2
  const UserTenantsMapping = require('../models/UserTenantsMapping');
3
+ const { isSuperAdmin } = require('./systemScope');
3
4
 
4
5
  var SLOT_KEYS = ['l1', 'l2', 'l3', 'l4'];
5
6
 
@@ -10,6 +11,9 @@ var SLOT_KEYS = ['l1', 'l2', 'l3', 'l4'];
10
11
  * use it. Mount AFTER authMiddleware (needs req.user.id) and AFTER
11
12
  * @xeplr/db's mtMiddleware() (reads the same headers).
12
13
  *
14
+ * Super Admin passes whatever the headers say: the role runs the whole
15
+ * install, so it is a member of every company by definition.
16
+ *
13
17
  * A header that's simply absent is left alone — the existing fail-closed
14
18
  * query modifier in BaseModel already handles "missing" (empty result set).
15
19
  * This only rejects a PRESENT but unauthorized value (403).
@@ -32,6 +36,9 @@ function mtMembershipMiddleware(options) {
32
36
  try {
33
37
  var mtConfig = getMtConfig();
34
38
  if (!mtConfig.enabled || !req.user || !req.user.id) return next();
39
+ // Super Admin goes into any company and workspace: running the whole
40
+ // install is the role. Everyone else needs a membership row per value.
41
+ if (isSuperAdmin(req.user)) return next();
35
42
 
36
43
  for (var i = 0; i < SLOT_KEYS.length; i++) {
37
44
  var key = SLOT_KEYS[i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/auth",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Pluggable authentication service: register, login, forgot/reset password, RBAC, multi-tenancy",
5
5
  "main": "index.js",
6
6
  "files": [