@objectstack/plugin-auth 6.8.1 → 7.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/dist/index.js CHANGED
@@ -69,6 +69,7 @@ module.exports = __toCommonJS(index_exports);
69
69
 
70
70
  // src/auth-plugin.ts
71
71
  var import_apps = require("@objectstack/platform-objects/apps");
72
+ var import_pages = require("@objectstack/platform-objects/pages");
72
73
 
73
74
  // src/objectql-adapter.ts
74
75
  var import_adapters = require("better-auth/adapters");
@@ -694,8 +695,7 @@ var AuthManager = class {
694
695
  relatedId: user.id
695
696
  });
696
697
  } catch (err) {
697
- console.error(`[AuthManager] sendResetPassword failed: ${err?.message ?? err}`);
698
- throw err;
698
+ console.error(`[AuthManager] sendResetPassword failed (swallowed): ${err?.message ?? err}`);
699
699
  }
700
700
  }
701
701
  };
@@ -731,8 +731,7 @@ var AuthManager = class {
731
731
  relatedId: user.id
732
732
  });
733
733
  } catch (err) {
734
- console.error(`[AuthManager] sendVerificationEmail failed: ${err?.message ?? err}`);
735
- throw err;
734
+ console.error(`[AuthManager] sendVerificationEmail failed (swallowed): ${err?.message ?? err}`);
736
735
  }
737
736
  }
738
737
  }
@@ -873,12 +872,14 @@ var AuthManager = class {
873
872
  async buildPluginList() {
874
873
  const pluginConfig = this.config.plugins ?? {};
875
874
  const plugins = [];
875
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
876
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
876
877
  const enabled = {
877
878
  organization: pluginConfig.organization ?? true,
878
879
  twoFactor: pluginConfig.twoFactor ?? false,
879
880
  passkeys: pluginConfig.passkeys ?? false,
880
881
  magicLink: pluginConfig.magicLink ?? false,
881
- oidcProvider: pluginConfig.oidcProvider ?? false,
882
+ oidcProvider: oidcFromEnv ?? pluginConfig.oidcProvider ?? false,
882
883
  deviceAuthorization: pluginConfig.deviceAuthorization ?? false,
883
884
  admin: pluginConfig.admin ?? false
884
885
  };
@@ -937,14 +938,18 @@ var AuthManager = class {
937
938
  // never seed `sys_environment`) keep working: any lookup error
938
939
  // is treated as "no envs to protect".
939
940
  organizationHooks: {
940
- // Gate fresh organization creation behind `OS_MULTI_ORG_ENABLED`.
941
+ // Gate fresh organization creation behind the multi-org flag.
941
942
  // The plugin itself is always installed (so list/update/invite endpoints
942
943
  // keep responding); only the `create` operation is denied when the
943
- // deployment is provisioned in single-org mode. Default is enabled
944
- // to preserve historical behaviour.
944
+ // deployment is provisioned in single-org mode. Resolution order:
945
+ // 1. explicit `OS_MULTI_ORG_ENABLED` (wins for backwards compat),
946
+ // 2. else `OS_MULTI_TENANT` (multi-tenant deployments are always
947
+ // multi-org), default `'false'` → single-org / per-env runtime.
945
948
  beforeCreateOrganization: async () => {
949
+ const env = globalThis?.process?.env ?? {};
950
+ const explicit = env.OS_MULTI_ORG_ENABLED;
946
951
  const flag = String(
947
- globalThis?.process?.env?.OS_MULTI_ORG_ENABLED ?? "true"
952
+ explicit ?? env.OS_MULTI_TENANT ?? "false"
948
953
  ).toLowerCase();
949
954
  if (flag === "false") {
950
955
  const { APIError } = await import("better-auth/api");
@@ -1019,8 +1024,7 @@ var AuthManager = class {
1019
1024
  relatedId: invitation.id
1020
1025
  });
1021
1026
  } catch (err) {
1022
- console.error(`[AuthManager] sendInvitationEmail failed: ${err?.message ?? err}`);
1023
- throw err;
1027
+ console.error(`[AuthManager] sendInvitationEmail failed (swallowed): ${err?.message ?? err}`);
1024
1028
  }
1025
1029
  }
1026
1030
  }));
@@ -1335,8 +1339,9 @@ var AuthManager = class {
1335
1339
  requireEmailVerification: emailPasswordConfig.requireEmailVerification ?? false
1336
1340
  };
1337
1341
  const pluginConfig = this.config.plugins ?? {};
1342
+ const multiOrgEnv = globalThis?.process?.env ?? {};
1338
1343
  const multiOrgEnabled = String(
1339
- globalThis?.process?.env?.OS_MULTI_ORG_ENABLED ?? "true"
1344
+ multiOrgEnv.OS_MULTI_ORG_ENABLED ?? multiOrgEnv.OS_MULTI_TENANT ?? "false"
1340
1345
  ).toLowerCase() !== "false";
1341
1346
  const DEFAULT_TERMS_URL = "https://objectstack.ai/terms";
1342
1347
  const DEFAULT_PRIVACY_URL = "https://objectstack.ai/privacy";
@@ -1350,13 +1355,15 @@ var AuthManager = class {
1350
1355
  };
1351
1356
  const termsUrl = resolveLegalUrl(rawTermsUrl, DEFAULT_TERMS_URL);
1352
1357
  const privacyUrl = resolveLegalUrl(rawPrivacyUrl, DEFAULT_PRIVACY_URL);
1358
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
1359
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
1353
1360
  const features = {
1354
1361
  twoFactor: pluginConfig.twoFactor ?? false,
1355
1362
  passkeys: pluginConfig.passkeys ?? false,
1356
1363
  magicLink: pluginConfig.magicLink ?? false,
1357
1364
  organization: pluginConfig.organization ?? true,
1358
1365
  multiOrgEnabled,
1359
- oidcProvider: pluginConfig.oidcProvider ?? false,
1366
+ oidcProvider: oidcFromEnv ?? pluginConfig.oidcProvider ?? false,
1360
1367
  deviceAuthorization: pluginConfig.deviceAuthorization ?? false,
1361
1368
  ...termsUrl ? { termsUrl } : {},
1362
1369
  ...privacyUrl ? { privacyUrl } : {}
@@ -1448,7 +1455,12 @@ var AuthPlugin = class {
1448
1455
  // @objectstack/platform-objects/apps). plugin-auth is the natural
1449
1456
  // owner of its registration since it loads first among the trio
1450
1457
  // (auth + security + audit) that supplies the underlying objects.
1451
- apps: [import_apps.SETUP_APP, import_apps.STUDIO_APP],
1458
+ apps: [import_apps.SETUP_APP, import_apps.STUDIO_APP, import_apps.ACCOUNT_APP],
1459
+ // Slotted record-detail pages for system objects — currently
1460
+ // sys_organization gets a Members / Invitations / Teams tab strip
1461
+ // (see SysOrganizationDetailPage for the rationale and the
1462
+ // intentionally-omitted OAuth / SSO tabs).
1463
+ pages: [import_pages.SysOrganizationDetailPage, import_pages.SysUserDetailPage],
1452
1464
  // List views for each Setup-nav object are defined on the schema
1453
1465
  // itself via the canonical `listViews` map (e.g.
1454
1466
  // sys_user.listViews.{all_users,unverified,two_factor}). Registering
@@ -1467,30 +1479,6 @@ var AuthPlugin = class {
1467
1479
  if (!this.authManager) {
1468
1480
  throw new Error("Auth manager not initialized");
1469
1481
  }
1470
- ctx.hook("kernel:ready", async () => {
1471
- try {
1472
- const i18n = ctx.getService("i18n");
1473
- let loaded = 0;
1474
- for (const [locale, data] of Object.entries(import_apps.SetupAppTranslations)) {
1475
- if (data && typeof data === "object") {
1476
- try {
1477
- i18n.loadTranslations(locale, data);
1478
- loaded++;
1479
- } catch (err) {
1480
- ctx.logger.warn(
1481
- `Auth: failed to load Setup App translations for '${locale}': ${err?.message ?? err}`
1482
- );
1483
- }
1484
- }
1485
- }
1486
- if (loaded > 0) {
1487
- ctx.logger.info(
1488
- `Auth: contributed Setup App translations (${loaded} locale${loaded > 1 ? "s" : ""})`
1489
- );
1490
- }
1491
- } catch {
1492
- }
1493
- });
1494
1482
  if (this.options.registerRoutes) {
1495
1483
  ctx.hook("kernel:ready", async () => {
1496
1484
  if (this.authManager) {
@@ -1748,7 +1736,10 @@ var AuthPlugin = class {
1748
1736
  );
1749
1737
  }
1750
1738
  });
1751
- if (this.options.plugins?.oidcProvider) {
1739
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
1740
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
1741
+ const oidcEnabled = oidcFromEnv ?? this.options.plugins?.oidcProvider ?? false;
1742
+ if (oidcEnabled) {
1752
1743
  void this.registerOidcDiscoveryRoutes(rawApp, ctx).catch((error) => {
1753
1744
  ctx.logger.error("Failed to register OIDC discovery routes", error);
1754
1745
  });