@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.mjs CHANGED
@@ -2,9 +2,10 @@
2
2
  import {
3
3
  SETUP_APP,
4
4
  STUDIO_APP,
5
- SystemOverviewDashboard,
6
- SetupAppTranslations
5
+ ACCOUNT_APP,
6
+ SystemOverviewDashboard
7
7
  } from "@objectstack/platform-objects/apps";
8
+ import { SysOrganizationDetailPage, SysUserDetailPage } from "@objectstack/platform-objects/pages";
8
9
 
9
10
  // src/objectql-adapter.ts
10
11
  import { createAdapterFactory } from "better-auth/adapters";
@@ -630,8 +631,7 @@ var AuthManager = class {
630
631
  relatedId: user.id
631
632
  });
632
633
  } catch (err) {
633
- console.error(`[AuthManager] sendResetPassword failed: ${err?.message ?? err}`);
634
- throw err;
634
+ console.error(`[AuthManager] sendResetPassword failed (swallowed): ${err?.message ?? err}`);
635
635
  }
636
636
  }
637
637
  };
@@ -667,8 +667,7 @@ var AuthManager = class {
667
667
  relatedId: user.id
668
668
  });
669
669
  } catch (err) {
670
- console.error(`[AuthManager] sendVerificationEmail failed: ${err?.message ?? err}`);
671
- throw err;
670
+ console.error(`[AuthManager] sendVerificationEmail failed (swallowed): ${err?.message ?? err}`);
672
671
  }
673
672
  }
674
673
  }
@@ -809,12 +808,14 @@ var AuthManager = class {
809
808
  async buildPluginList() {
810
809
  const pluginConfig = this.config.plugins ?? {};
811
810
  const plugins = [];
811
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
812
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
812
813
  const enabled = {
813
814
  organization: pluginConfig.organization ?? true,
814
815
  twoFactor: pluginConfig.twoFactor ?? false,
815
816
  passkeys: pluginConfig.passkeys ?? false,
816
817
  magicLink: pluginConfig.magicLink ?? false,
817
- oidcProvider: pluginConfig.oidcProvider ?? false,
818
+ oidcProvider: oidcFromEnv ?? pluginConfig.oidcProvider ?? false,
818
819
  deviceAuthorization: pluginConfig.deviceAuthorization ?? false,
819
820
  admin: pluginConfig.admin ?? false
820
821
  };
@@ -873,14 +874,18 @@ var AuthManager = class {
873
874
  // never seed `sys_environment`) keep working: any lookup error
874
875
  // is treated as "no envs to protect".
875
876
  organizationHooks: {
876
- // Gate fresh organization creation behind `OS_MULTI_ORG_ENABLED`.
877
+ // Gate fresh organization creation behind the multi-org flag.
877
878
  // The plugin itself is always installed (so list/update/invite endpoints
878
879
  // keep responding); only the `create` operation is denied when the
879
- // deployment is provisioned in single-org mode. Default is enabled
880
- // to preserve historical behaviour.
880
+ // deployment is provisioned in single-org mode. Resolution order:
881
+ // 1. explicit `OS_MULTI_ORG_ENABLED` (wins for backwards compat),
882
+ // 2. else `OS_MULTI_TENANT` (multi-tenant deployments are always
883
+ // multi-org), default `'false'` → single-org / per-env runtime.
881
884
  beforeCreateOrganization: async () => {
885
+ const env = globalThis?.process?.env ?? {};
886
+ const explicit = env.OS_MULTI_ORG_ENABLED;
882
887
  const flag = String(
883
- globalThis?.process?.env?.OS_MULTI_ORG_ENABLED ?? "true"
888
+ explicit ?? env.OS_MULTI_TENANT ?? "false"
884
889
  ).toLowerCase();
885
890
  if (flag === "false") {
886
891
  const { APIError } = await import("better-auth/api");
@@ -955,8 +960,7 @@ var AuthManager = class {
955
960
  relatedId: invitation.id
956
961
  });
957
962
  } catch (err) {
958
- console.error(`[AuthManager] sendInvitationEmail failed: ${err?.message ?? err}`);
959
- throw err;
963
+ console.error(`[AuthManager] sendInvitationEmail failed (swallowed): ${err?.message ?? err}`);
960
964
  }
961
965
  }
962
966
  }));
@@ -1271,8 +1275,9 @@ var AuthManager = class {
1271
1275
  requireEmailVerification: emailPasswordConfig.requireEmailVerification ?? false
1272
1276
  };
1273
1277
  const pluginConfig = this.config.plugins ?? {};
1278
+ const multiOrgEnv = globalThis?.process?.env ?? {};
1274
1279
  const multiOrgEnabled = String(
1275
- globalThis?.process?.env?.OS_MULTI_ORG_ENABLED ?? "true"
1280
+ multiOrgEnv.OS_MULTI_ORG_ENABLED ?? multiOrgEnv.OS_MULTI_TENANT ?? "false"
1276
1281
  ).toLowerCase() !== "false";
1277
1282
  const DEFAULT_TERMS_URL = "https://objectstack.ai/terms";
1278
1283
  const DEFAULT_PRIVACY_URL = "https://objectstack.ai/privacy";
@@ -1286,13 +1291,15 @@ var AuthManager = class {
1286
1291
  };
1287
1292
  const termsUrl = resolveLegalUrl(rawTermsUrl, DEFAULT_TERMS_URL);
1288
1293
  const privacyUrl = resolveLegalUrl(rawPrivacyUrl, DEFAULT_PRIVACY_URL);
1294
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
1295
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
1289
1296
  const features = {
1290
1297
  twoFactor: pluginConfig.twoFactor ?? false,
1291
1298
  passkeys: pluginConfig.passkeys ?? false,
1292
1299
  magicLink: pluginConfig.magicLink ?? false,
1293
1300
  organization: pluginConfig.organization ?? true,
1294
1301
  multiOrgEnabled,
1295
- oidcProvider: pluginConfig.oidcProvider ?? false,
1302
+ oidcProvider: oidcFromEnv ?? pluginConfig.oidcProvider ?? false,
1296
1303
  deviceAuthorization: pluginConfig.deviceAuthorization ?? false,
1297
1304
  ...termsUrl ? { termsUrl } : {},
1298
1305
  ...privacyUrl ? { privacyUrl } : {}
@@ -1403,7 +1410,12 @@ var AuthPlugin = class {
1403
1410
  // @objectstack/platform-objects/apps). plugin-auth is the natural
1404
1411
  // owner of its registration since it loads first among the trio
1405
1412
  // (auth + security + audit) that supplies the underlying objects.
1406
- apps: [SETUP_APP, STUDIO_APP],
1413
+ apps: [SETUP_APP, STUDIO_APP, ACCOUNT_APP],
1414
+ // Slotted record-detail pages for system objects — currently
1415
+ // sys_organization gets a Members / Invitations / Teams tab strip
1416
+ // (see SysOrganizationDetailPage for the rationale and the
1417
+ // intentionally-omitted OAuth / SSO tabs).
1418
+ pages: [SysOrganizationDetailPage, SysUserDetailPage],
1407
1419
  // List views for each Setup-nav object are defined on the schema
1408
1420
  // itself via the canonical `listViews` map (e.g.
1409
1421
  // sys_user.listViews.{all_users,unverified,two_factor}). Registering
@@ -1422,30 +1434,6 @@ var AuthPlugin = class {
1422
1434
  if (!this.authManager) {
1423
1435
  throw new Error("Auth manager not initialized");
1424
1436
  }
1425
- ctx.hook("kernel:ready", async () => {
1426
- try {
1427
- const i18n = ctx.getService("i18n");
1428
- let loaded = 0;
1429
- for (const [locale, data] of Object.entries(SetupAppTranslations)) {
1430
- if (data && typeof data === "object") {
1431
- try {
1432
- i18n.loadTranslations(locale, data);
1433
- loaded++;
1434
- } catch (err) {
1435
- ctx.logger.warn(
1436
- `Auth: failed to load Setup App translations for '${locale}': ${err?.message ?? err}`
1437
- );
1438
- }
1439
- }
1440
- }
1441
- if (loaded > 0) {
1442
- ctx.logger.info(
1443
- `Auth: contributed Setup App translations (${loaded} locale${loaded > 1 ? "s" : ""})`
1444
- );
1445
- }
1446
- } catch {
1447
- }
1448
- });
1449
1437
  if (this.options.registerRoutes) {
1450
1438
  ctx.hook("kernel:ready", async () => {
1451
1439
  if (this.authManager) {
@@ -1703,7 +1691,10 @@ var AuthPlugin = class {
1703
1691
  );
1704
1692
  }
1705
1693
  });
1706
- if (this.options.plugins?.oidcProvider) {
1694
+ const oidcEnv = globalThis?.process?.env?.OS_OIDC_PROVIDER_ENABLED;
1695
+ const oidcFromEnv = oidcEnv != null ? String(oidcEnv).toLowerCase() === "true" : void 0;
1696
+ const oidcEnabled = oidcFromEnv ?? this.options.plugins?.oidcProvider ?? false;
1697
+ if (oidcEnabled) {
1707
1698
  void this.registerOidcDiscoveryRoutes(rawApp, ctx).catch((error) => {
1708
1699
  ctx.logger.error("Failed to register OIDC discovery routes", error);
1709
1700
  });