@skylabs-digital/react-identity-access 2.21.0 → 2.22.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.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
- import { createContext as fe, useMemo as Z, useState as T, useCallback as se, useEffect as ee, useContext as le, useRef as Ke } from "react";
3
- import { useLocation as ke, Navigate as Se, useNavigate as gt, useSearchParams as mt } from "react-router-dom";
2
+ import { createContext as me, useMemo as Z, useState as T, useCallback as ie, useEffect as ee, useContext as le, useRef as Ke } from "react";
3
+ import { useLocation as Ae, Navigate as Te, useNavigate as gt, useSearchParams as mt } from "react-router-dom";
4
4
  class ce {
5
5
  constructor(e, t = 1e4) {
6
6
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
@@ -109,7 +109,7 @@ class ze {
109
109
  })).data;
110
110
  }
111
111
  }
112
- const Fe = fe(null);
112
+ const Fe = me(null);
113
113
  function yr({ config: n, children: e }) {
114
114
  const t = Z(
115
115
  () => {
@@ -145,7 +145,7 @@ function yr({ config: n, children: e }) {
145
145
  appError: f,
146
146
  retryApp: p
147
147
  };
148
- }, [n, r, o, f]), c = se(
148
+ }, [n, r, o, f]), c = ie(
149
149
  async (p = !1) => {
150
150
  if (!(!p && t.enabled && r))
151
151
  try {
@@ -170,7 +170,7 @@ function yr({ config: n, children: e }) {
170
170
  }
171
171
  },
172
172
  [n.baseUrl, n.appId, t, r]
173
- ), I = se(async () => {
173
+ ), I = ie(async () => {
174
174
  if (!(!t.enabled || !r))
175
175
  try {
176
176
  const p = localStorage.getItem(t.storageKey);
@@ -194,7 +194,7 @@ function yr({ config: n, children: e }) {
194
194
  r ? I() : c();
195
195
  }, []), /* @__PURE__ */ s(Fe.Provider, { value: w, children: e });
196
196
  }
197
- function ve() {
197
+ function ke() {
198
198
  const n = le(Fe);
199
199
  if (!n)
200
200
  throw new Error("useApp must be used within an AppProvider");
@@ -203,8 +203,8 @@ function ve() {
203
203
  function Ze() {
204
204
  return le(Fe);
205
205
  }
206
- const wr = ve;
207
- class ie extends Error {
206
+ const wr = ke;
207
+ class se extends Error {
208
208
  constructor(e, t) {
209
209
  const r = {
210
210
  token_expired: "Refresh token has expired",
@@ -228,7 +228,7 @@ class wt extends Error {
228
228
  }
229
229
  const oe = class oe {
230
230
  constructor(e = {}) {
231
- this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.onSessionExpired = e.onSessionExpired, this.baseUrl = e.baseUrl || "", this.proactiveRefreshMargin = e.proactiveRefreshMargin ?? 6e4, this.refreshQueueTimeout = e.refreshQueueTimeout ?? 1e4, this.maxRefreshRetries = e.maxRefreshRetries ?? 3, this.retryBackoffBase = e.retryBackoffBase ?? 1e3, this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey), this.scheduleProactiveRefresh();
231
+ this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.onSessionExpired = e.onSessionExpired, this.baseUrl = e.baseUrl || "", this.proactiveRefreshMargin = e.proactiveRefreshMargin ?? 6e4, this.refreshQueueTimeout = e.refreshQueueTimeout ?? 1e4, this.maxRefreshRetries = e.maxRefreshRetries ?? 3, this.retryBackoffBase = e.retryBackoffBase ?? 1e3, this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey), this.scheduleProactiveRefresh();
232
232
  }
233
233
  /**
234
234
  * Get or create a SessionManager instance for the given config.
@@ -350,15 +350,29 @@ const oe = class oe {
350
350
  backgroundRefresh() {
351
351
  if (this.isDestroyed) return;
352
352
  const e = this.getTokens();
353
- e != null && e.refreshToken && (this.refreshPromise || this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
354
- }).catch((t) => {
355
- t instanceof ie || (console.warn(
353
+ if (!(e != null && e.refreshToken) || this.refreshPromise) return;
354
+ const t = this.sessionGeneration;
355
+ this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
356
+ }).catch((r) => {
357
+ r instanceof se || this.sessionGeneration === t && (console.warn(
356
358
  "[SessionManager] Background refresh failed, retrying in 30s:",
357
- t.message
359
+ r.message
358
360
  ), this.backgroundRetryTimerId = setTimeout(() => {
359
361
  this.backgroundRefresh();
360
362
  }, 3e4));
361
- }));
363
+ });
364
+ }
365
+ /**
366
+ * Wait for any in-progress token refresh to settle.
367
+ * Returns true if refresh succeeded, false if it failed or no refresh was pending.
368
+ */
369
+ async waitForPendingRefresh() {
370
+ if (!this.refreshPromise) return !1;
371
+ try {
372
+ return await this.refreshPromise, !0;
373
+ } catch {
374
+ return !1;
375
+ }
362
376
  }
363
377
  // --- Core: getValidAccessToken with queue + timeout ---
364
378
  /**
@@ -372,13 +386,13 @@ const oe = class oe {
372
386
  async getValidAccessToken() {
373
387
  const e = this.getTokens();
374
388
  if (!(e != null && e.accessToken)) {
375
- const t = new ie("token_invalid", "No tokens available");
389
+ const t = new se("token_invalid", "No tokens available");
376
390
  throw this.handleSessionExpired(t), t;
377
391
  }
378
392
  if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
379
393
  return e.accessToken;
380
394
  if (!e.refreshToken) {
381
- const t = new ie("token_invalid", "No refresh token available");
395
+ const t = new se("token_invalid", "No refresh token available");
382
396
  throw this.handleSessionExpired(t), t;
383
397
  }
384
398
  return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
@@ -390,7 +404,7 @@ const oe = class oe {
390
404
  try {
391
405
  return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
392
406
  } catch (e) {
393
- return e instanceof ie && this.onRefreshFailed && this.onRefreshFailed(), {};
407
+ return e instanceof se && this.onRefreshFailed && this.onRefreshFailed(), {};
394
408
  }
395
409
  }
396
410
  enqueueForToken() {
@@ -410,7 +424,7 @@ const oe = class oe {
410
424
  return this.resolveQueue(r), r;
411
425
  } catch (t) {
412
426
  const r = t instanceof Error ? t : new Error("Token refresh failed");
413
- throw r instanceof ie ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
427
+ throw r instanceof se ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
414
428
  } finally {
415
429
  this.refreshPromise = null;
416
430
  }
@@ -430,19 +444,23 @@ const oe = class oe {
430
444
  // --- Refresh with retry + error classification ---
431
445
  async executeRefreshWithRetry(e) {
432
446
  let t;
433
- for (let r = 0; r <= this.maxRefreshRetries; r++)
447
+ const r = this.sessionGeneration;
448
+ for (let i = 0; i <= this.maxRefreshRetries; i++) {
449
+ if (this.sessionGeneration !== r)
450
+ throw new se("token_invalid", "Session cleared during refresh");
434
451
  try {
435
452
  await this.performTokenRefresh(e);
436
453
  return;
437
- } catch (i) {
438
- const o = i instanceof Error ? i : new Error(String(i));
439
- if (o instanceof ie)
440
- throw o;
441
- if (t = o, r < this.maxRefreshRetries) {
442
- const a = this.retryBackoffBase * Math.pow(2, r);
443
- await this.sleep(a);
454
+ } catch (o) {
455
+ const a = o instanceof Error ? o : new Error(String(o));
456
+ if (a instanceof se)
457
+ throw a;
458
+ if (t = a, i < this.maxRefreshRetries) {
459
+ const f = this.retryBackoffBase * Math.pow(2, i);
460
+ await this.sleep(f);
444
461
  }
445
462
  }
463
+ }
446
464
  throw new wt(this.maxRefreshRetries + 1, t);
447
465
  }
448
466
  /**
@@ -472,7 +490,7 @@ const oe = class oe {
472
490
  } catch {
473
491
  o = r.statusText.toLowerCase();
474
492
  }
475
- throw r.status === 401 ? o.includes("expired") ? new ie("token_expired") : o.includes("invalid") ? new ie("token_invalid") : new ie("token_invalid", `Unauthorized: ${o}`) : r.status === 400 ? o.includes("inactive") ? new ie("user_inactive") : new Error(`Token refresh failed (400): ${o}`) : new Error(`Token refresh failed: ${r.status} ${o}`);
493
+ throw r.status === 401 ? o.includes("expired") ? new se("token_expired") : o.includes("invalid") ? new se("token_invalid") : new se("token_invalid", `Unauthorized: ${o}`) : r.status === 400 ? o.includes("inactive") ? new se("user_inactive") : new Error(`Token refresh failed (400): ${o}`) : new Error(`Token refresh failed: ${r.status} ${o}`);
476
494
  }
477
495
  const i = await r.json();
478
496
  this.setTokens({
@@ -500,8 +518,8 @@ const oe = class oe {
500
518
  }
501
519
  // --- Session lifecycle ---
502
520
  clearSession() {
503
- this.cancelProactiveTimer(), this.clearTokens(), this.clearUser();
504
- const e = new ie("token_invalid", "Session cleared");
521
+ this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens(), this.clearUser();
522
+ const e = new se("token_invalid", "Session cleared");
505
523
  this.rejectQueue(e);
506
524
  }
507
525
  /**
@@ -510,7 +528,7 @@ const oe = class oe {
510
528
  */
511
529
  destroy() {
512
530
  this.isDestroyed = !0, oe.instances.delete(this.storageKey), this.cancelProactiveTimer();
513
- const e = new ie("token_invalid", "SessionManager destroyed");
531
+ const e = new se("token_invalid", "SessionManager destroyed");
514
532
  this.rejectQueue(e);
515
533
  }
516
534
  // --- JWT helpers ---
@@ -549,7 +567,7 @@ const oe = class oe {
549
567
  }
550
568
  };
551
569
  oe.instances = /* @__PURE__ */ new Map();
552
- let we = oe;
570
+ let Se = oe;
553
571
  class bt {
554
572
  constructor(e) {
555
573
  this.httpService = e;
@@ -722,7 +740,7 @@ class St {
722
740
  });
723
741
  }
724
742
  }
725
- class be {
743
+ class ve {
726
744
  constructor(e, t, r) {
727
745
  this.httpService = e, this.appId = t, this.sessionManager = r;
728
746
  }
@@ -830,7 +848,7 @@ function xt(n, e, t) {
830
848
  const r = e.split(".");
831
849
  return r.length === 2 ? `${n}.${e}` : r.length >= 3 ? (r[0] = n, r.join(".")) : null;
832
850
  }
833
- const pe = "_auth";
851
+ const ge = "_auth";
834
852
  function We(n) {
835
853
  const e = JSON.stringify(n);
836
854
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
@@ -849,7 +867,7 @@ function At(n) {
849
867
  function Pt() {
850
868
  if (typeof window > "u")
851
869
  return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
852
- const e = new URLSearchParams(window.location.search).get(pe);
870
+ const e = new URLSearchParams(window.location.search).get(ge);
853
871
  if (console.log("[CrossDomainAuth] extractAuthTokensFromUrl called", {
854
872
  hasAuthParam: !!e,
855
873
  searchParams: window.location.search,
@@ -866,14 +884,14 @@ function Pt() {
866
884
  function Rt() {
867
885
  if (typeof window > "u") return;
868
886
  const n = new URL(window.location.href);
869
- n.searchParams.delete(pe), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
887
+ n.searchParams.delete(ge), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
870
888
  oldUrl: window.location.href,
871
889
  newUrl: n.toString()
872
890
  }), window.history.replaceState({}, "", n.toString());
873
891
  }
874
- const De = fe(null);
892
+ const De = me(null);
875
893
  function br({ config: n, children: e }) {
876
- const { baseUrl: t, appInfo: r, appId: i } = ve(), o = se(() => typeof window > "u" ? null : kt(
894
+ const { baseUrl: t, appInfo: r, appId: i } = ke(), o = ie(() => typeof window > "u" ? null : kt(
877
895
  {
878
896
  tenantMode: n.tenantMode || "selector",
879
897
  baseDomain: n.baseDomain,
@@ -913,12 +931,12 @@ function br({ config: n, children: e }) {
913
931
  const h = o();
914
932
  f(h);
915
933
  }, [o, n.tenantMode]);
916
- const M = (r == null ? void 0 : r.settingsSchema) || null, L = se(
934
+ const M = (r == null ? void 0 : r.settingsSchema) || null, L = ie(
917
935
  async (h, C = !1) => {
918
936
  if (!(!C && g.enabled && w && w.domain === h))
919
937
  try {
920
938
  p(!0), R(null);
921
- const S = new ce(t), y = await new be(S, i).getPublicTenantInfo(h);
939
+ const S = new ce(t), y = await new ve(S, i).getPublicTenantInfo(h);
922
940
  if (c(y), g.enabled)
923
941
  try {
924
942
  const v = {
@@ -938,30 +956,30 @@ function br({ config: n, children: e }) {
938
956
  }
939
957
  },
940
958
  [t, i, g, w]
941
- ), D = se(async () => {
959
+ ), D = ie(async () => {
942
960
  if (!(!g.enabled || !w || !a))
943
961
  try {
944
962
  const h = localStorage.getItem(g.storageKey);
945
963
  if (!h) return;
946
964
  const C = JSON.parse(h);
947
965
  if (Date.now() - C.timestamp > g.ttl * 0.5) {
948
- const b = new ce(t), v = await new be(b, i).getPublicTenantInfo(a);
966
+ const b = new ce(t), v = await new ve(b, i).getPublicTenantInfo(a);
949
967
  c(v);
950
- const j = {
968
+ const G = {
951
969
  data: v,
952
970
  timestamp: Date.now(),
953
971
  tenantSlug: a
954
972
  };
955
- localStorage.setItem(g.storageKey, JSON.stringify(j));
973
+ localStorage.setItem(g.storageKey, JSON.stringify(G));
956
974
  }
957
975
  } catch (h) {
958
976
  console.warn("Background tenant refresh failed:", h);
959
977
  }
960
- }, [t, i, g, w, a]), P = se(async () => {
978
+ }, [t, i, g, w, a]), P = ie(async () => {
961
979
  if (w != null && w.id)
962
980
  try {
963
981
  u(!0), m(null);
964
- const h = new ce(t), S = await new be(h, w.appId).getTenantSettings(w.id);
982
+ const h = new ce(t), S = await new ve(h, w.appId).getTenantSettings(w.id);
965
983
  E(S);
966
984
  } catch (h) {
967
985
  const C = h instanceof Error ? h : new Error("Failed to load tenant settings");
@@ -969,9 +987,9 @@ function br({ config: n, children: e }) {
969
987
  } finally {
970
988
  u(!1);
971
989
  }
972
- }, [t, w]), U = se(() => {
990
+ }, [t, w]), U = ie(() => {
973
991
  P();
974
- }, [P]), l = se(
992
+ }, [P]), l = ie(
975
993
  (h) => {
976
994
  if (!M)
977
995
  return { isValid: !0, errors: [] };
@@ -986,8 +1004,8 @@ function br({ config: n, children: e }) {
986
1004
  }
987
1005
  if (y != null) {
988
1006
  if (b.type) {
989
- const j = b.type, Q = typeof y;
990
- j === "string" && Q !== "string" ? C.push(`Field '${S}' must be a string`) : (j === "number" || j === "integer") && Q !== "number" ? C.push(`Field '${S}' must be a number`) : j === "boolean" && Q !== "boolean" ? C.push(`Field '${S}' must be a boolean`) : j === "array" && !Array.isArray(y) && C.push(`Field '${S}' must be an array`);
1007
+ const G = b.type, Q = typeof y;
1008
+ G === "string" && Q !== "string" ? C.push(`Field '${S}' must be a string`) : (G === "number" || G === "integer") && Q !== "number" ? C.push(`Field '${S}' must be a number`) : G === "boolean" && Q !== "boolean" ? C.push(`Field '${S}' must be a boolean`) : G === "array" && !Array.isArray(y) && C.push(`Field '${S}' must be an array`);
991
1009
  }
992
1010
  b.minLength !== void 0 && typeof y == "string" && y.length < b.minLength && C.push(
993
1011
  `Field '${S}' must be at least ${b.minLength} characters long`
@@ -1013,7 +1031,7 @@ function br({ config: n, children: e }) {
1013
1031
  }, [n.initialTenant, a, w, L, D]), ee(() => {
1014
1032
  w != null && w.id ? P() : (E(null), m(null), u(!1));
1015
1033
  }, [w == null ? void 0 : w.id, P]);
1016
- const N = se(
1034
+ const N = ie(
1017
1035
  (h, C) => {
1018
1036
  const { mode: S = "reload", tokens: b, redirectPath: y } = C || {}, v = n.tenantMode || "selector";
1019
1037
  if (v === "fixed") {
@@ -1024,29 +1042,29 @@ function br({ config: n, children: e }) {
1024
1042
  return;
1025
1043
  }
1026
1044
  if (localStorage.setItem("tenant", h), v === "subdomain") {
1027
- const j = window.location.hostname, Q = xt(
1045
+ const G = window.location.hostname, Q = xt(
1028
1046
  h,
1029
- j,
1047
+ G,
1030
1048
  n.baseDomain
1031
1049
  );
1032
1050
  if (!Q) {
1033
1051
  console.warn(
1034
1052
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
1035
- j
1053
+ G
1036
1054
  );
1037
1055
  return;
1038
1056
  }
1039
1057
  const O = y || window.location.pathname, q = new URL(`${window.location.protocol}//${Q}${O}`);
1040
1058
  new URLSearchParams(window.location.search).forEach((B, X) => {
1041
- X !== pe && q.searchParams.set(X, B);
1042
- }), b && q.searchParams.set(pe, We(b)), window.location.href = q.toString();
1059
+ X !== ge && q.searchParams.set(X, B);
1060
+ }), b && q.searchParams.set(ge, We(b)), window.location.href = q.toString();
1043
1061
  } else if (v === "selector") {
1044
- const j = y || window.location.pathname, Q = new URLSearchParams(window.location.search);
1045
- if (Q.set(n.selectorParam || "tenant", h), Q.delete(pe), b && Q.set(pe, We(b)), S === "reload") {
1046
- const O = `${j}?${Q.toString()}${window.location.hash}`;
1062
+ const G = y || window.location.pathname, Q = new URLSearchParams(window.location.search);
1063
+ if (Q.set(n.selectorParam || "tenant", h), Q.delete(ge), b && Q.set(ge, We(b)), S === "reload") {
1064
+ const O = `${G}?${Q.toString()}${window.location.hash}`;
1047
1065
  window.location.href = O;
1048
1066
  } else {
1049
- const O = `${j}?${Q.toString()}${window.location.hash}`;
1067
+ const O = `${G}?${Q.toString()}${window.location.hash}`;
1050
1068
  window.history.pushState({}, "", O), f(h), L(h);
1051
1069
  }
1052
1070
  }
@@ -1086,18 +1104,18 @@ function br({ config: n, children: e }) {
1086
1104
  ]);
1087
1105
  return /* @__PURE__ */ s(De.Provider, { value: $, children: e });
1088
1106
  }
1089
- function ge() {
1107
+ function ye() {
1090
1108
  const n = le(De);
1091
1109
  if (!n)
1092
1110
  throw new Error("useTenant must be used within a TenantProvider");
1093
1111
  return n;
1094
1112
  }
1095
- function xe() {
1113
+ function Pe() {
1096
1114
  return le(De);
1097
1115
  }
1098
- const Sr = ge;
1116
+ const Sr = ye;
1099
1117
  function vr() {
1100
- const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ge();
1118
+ const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ye();
1101
1119
  return {
1102
1120
  settings: n,
1103
1121
  settingsSchema: e,
@@ -1106,8 +1124,8 @@ function vr() {
1106
1124
  validateSettings: i
1107
1125
  };
1108
1126
  }
1109
- function me() {
1110
- const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = ge();
1127
+ function we() {
1128
+ const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = ye();
1111
1129
  return {
1112
1130
  tenant: n,
1113
1131
  tenantSlug: e,
@@ -1116,12 +1134,12 @@ function me() {
1116
1134
  retry: i
1117
1135
  };
1118
1136
  }
1119
- const Ne = fe(null);
1137
+ const Ne = me(null);
1120
1138
  function Tr({ config: n = {}, children: e }) {
1121
- const { appId: t, baseUrl: r } = ve(), { tenant: i, tenantSlug: o, switchTenant: a } = ge(), [f, g] = T(n.initialRoles || []), [w, c] = T(!n.initialRoles), [I, p] = T(null), [x, R] = T(!1), [F, E] = T(null), [A, u] = T(0), [k, m] = T(() => {
1139
+ const { appId: t, baseUrl: r } = ke(), { tenant: i, tenantSlug: o, switchTenant: a } = ye(), [f, g] = T(n.initialRoles || []), [w, c] = T(!n.initialRoles), [I, p] = T(null), [x, R] = T(!1), [F, E] = T(null), [A, u] = T(0), [k, m] = T(() => {
1122
1140
  try {
1123
- const G = localStorage.getItem("userTenants");
1124
- return G ? JSON.parse(G) : [];
1141
+ const V = localStorage.getItem("userTenants");
1142
+ return V ? JSON.parse(V) : [];
1125
1143
  } catch {
1126
1144
  return [];
1127
1145
  }
@@ -1130,10 +1148,10 @@ function Tr({ config: n = {}, children: e }) {
1130
1148
  "[AuthProvider] SYNC: URL tokens found, will block isAuthReady until user loaded"
1131
1149
  ));
1132
1150
  const [P, U] = T(() => {
1133
- const G = D.current.urlTokens !== null;
1134
- return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", G), G;
1151
+ const V = D.current.urlTokens !== null;
1152
+ return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", V), V;
1135
1153
  }), l = Z(() => {
1136
- const G = we.getInstance({
1154
+ const V = Se.getInstance({
1137
1155
  tenantSlug: o,
1138
1156
  baseUrl: r,
1139
1157
  refreshQueueTimeout: n.refreshQueueTimeout,
@@ -1147,29 +1165,33 @@ function Tr({ config: n = {}, children: e }) {
1147
1165
  n.onSessionExpired ? n.onSessionExpired(he) : n.onRefreshFailed && n.onRefreshFailed();
1148
1166
  }
1149
1167
  });
1150
- return D.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), G.setTokens({
1168
+ return D.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), V.setTokens({
1151
1169
  accessToken: D.current.urlTokens.accessToken,
1152
1170
  refreshToken: D.current.urlTokens.refreshToken,
1153
1171
  expiresIn: D.current.urlTokens.expiresIn
1154
- }), console.log("[AuthProvider] SYNC: Session valid:", G.hasValidSession())), G;
1155
- }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [N, $] = T(() => D.current.urlTokens ? !1 : l.hasValidSession()), h = D.current.done && !P && !N, C = Z(() => {
1156
- const G = new ce(r);
1157
- return G.setSessionManager(l), G;
1158
- }, [r, l]), S = Z(() => new bt(new ce(r)), [r]), b = Z(() => new St(C, l), [C, l]), y = Z(() => new _e(new ce(r)), [r]), v = Z(() => I || l.getUser(), [I, l]), j = Z(() => v != null && v.roleId && f.find((G) => G.id === v.roleId) || null, [v, f]), Q = Z(() => (j == null ? void 0 : j.permissions) || [], [j]), O = Z(() => l.hasValidSession() && I !== null, [l, I]), q = 5 * 60 * 1e3, W = Z(() => {
1159
- const G = async (H = !1) => {
1172
+ }), console.log("[AuthProvider] SYNC: Session valid:", V.hasValidSession())), V;
1173
+ }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [N, $] = T(() => {
1174
+ if (D.current.urlTokens) return !1;
1175
+ const V = l.getTokens();
1176
+ return V ? l.hasValidSession() || !!V.refreshToken : !1;
1177
+ }), h = D.current.done && !P && !N, C = Z(() => {
1178
+ const V = new ce(r);
1179
+ return V.setSessionManager(l), V;
1180
+ }, [r, l]), S = Z(() => new bt(new ce(r)), [r]), b = Z(() => new St(C, l), [C, l]), y = Z(() => new _e(new ce(r)), [r]), v = Z(() => I || l.getUser(), [I, l]), G = Z(() => v != null && v.roleId && f.find((V) => V.id === v.roleId) || null, [v, f]), Q = Z(() => (G == null ? void 0 : G.permissions) || [], [G]), O = Z(() => l.hasValidSession() && I !== null, [l, I]), q = 5 * 60 * 1e3, W = Z(() => {
1181
+ const V = async (H = !1) => {
1160
1182
  try {
1161
1183
  if (!l.hasValidSession())
1162
1184
  return;
1163
1185
  const z = Date.now();
1164
1186
  if (!H && z - A < q && I)
1165
1187
  return;
1166
- const V = l.getUserId();
1167
- if (!V) {
1188
+ const j = l.getUserId();
1189
+ if (!j) {
1168
1190
  console.warn("[AuthProvider] No userId available in token or storage");
1169
1191
  return;
1170
1192
  }
1171
1193
  R(!0), E(null);
1172
- const J = await b.getUserById(V);
1194
+ const J = await b.getUserById(j);
1173
1195
  p(J), l.setUser(J), u(Date.now());
1174
1196
  } catch (z) {
1175
1197
  const Y = z instanceof Error ? z : new Error("Failed to load user data");
@@ -1178,19 +1200,19 @@ function Tr({ config: n = {}, children: e }) {
1178
1200
  R(!1);
1179
1201
  }
1180
1202
  }, he = async () => {
1181
- await G();
1182
- }, Ae = async (H) => {
1203
+ await V();
1204
+ }, fe = async (H) => {
1183
1205
  var qe;
1184
- const { username: z, password: Y, tenantSlug: V, redirectPath: J } = H;
1206
+ const { username: z, password: Y, tenantSlug: j, redirectPath: J } = H;
1185
1207
  let te = i == null ? void 0 : i.id, re = o, ne = l;
1186
- V && (te = (await new be(C, t).getPublicTenantInfo(V)).id, re = V);
1208
+ j && (te = (await new ve(C, t).getPublicTenantInfo(j)).id, re = j);
1187
1209
  const K = await S.login({
1188
1210
  username: z,
1189
1211
  password: Y,
1190
1212
  appId: t,
1191
1213
  tenantId: te
1192
- }), ye = V && V !== o;
1193
- if (ye && (ne = new we({
1214
+ }), be = j && j !== o;
1215
+ if (be && (ne = new Se({
1194
1216
  tenantSlug: re,
1195
1217
  baseUrl: r
1196
1218
  })), ne.setTokens({
@@ -1200,9 +1222,9 @@ function Tr({ config: n = {}, children: e }) {
1200
1222
  }), K.user) {
1201
1223
  ne.setUser(K.user), p(K.user);
1202
1224
  try {
1203
- await G();
1204
- } catch (Te) {
1205
- console.warn("Failed to load complete user data after login:", Te);
1225
+ await V();
1226
+ } catch (xe) {
1227
+ console.warn("Failed to load complete user data after login:", xe);
1206
1228
  }
1207
1229
  }
1208
1230
  if (K.tenants && K.tenants.length > 0) {
@@ -1219,83 +1241,83 @@ function Tr({ config: n = {}, children: e }) {
1219
1241
  refreshToken: K.refreshToken,
1220
1242
  expiresIn: K.expiresIn
1221
1243
  };
1222
- if (ye && re)
1244
+ if (be && re)
1223
1245
  return a(re, { tokens: Ee, redirectPath: J }), K;
1224
1246
  if (J && J !== window.location.pathname)
1225
1247
  return a(re || o || "", { tokens: Ee, redirectPath: J }), K;
1226
1248
  if (!Ie && K.tenants && K.tenants.length > 0) {
1227
- const Te = H.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1228
- if (K.tenants.length === 1 && Te) {
1249
+ const xe = H.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1250
+ if (K.tenants.length === 1 && xe) {
1229
1251
  const Oe = K.tenants[0];
1230
1252
  return a(Oe.subdomain, { tokens: Ee, redirectPath: J }), K;
1231
1253
  } else K.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(K.tenants);
1232
1254
  }
1233
1255
  return K;
1234
- }, Pe = async (H) => {
1235
- const { email: z, phoneNumber: Y, name: V, password: J, lastName: te, tenantId: re } = H;
1256
+ }, pe = async (H) => {
1257
+ const { email: z, phoneNumber: Y, name: j, password: J, lastName: te, tenantId: re } = H;
1236
1258
  if (!z && !Y)
1237
1259
  throw new Error("Either email or phoneNumber is required");
1238
- if (!V || !J)
1260
+ if (!j || !J)
1239
1261
  throw new Error("Name and password are required");
1240
1262
  const ne = re ?? (i == null ? void 0 : i.id);
1241
1263
  return await S.signup({
1242
1264
  email: z,
1243
1265
  phoneNumber: Y,
1244
- name: V,
1266
+ name: j,
1245
1267
  password: J,
1246
1268
  tenantId: ne,
1247
1269
  lastName: te,
1248
1270
  appId: t
1249
1271
  });
1250
1272
  }, rt = async (H) => {
1251
- const { email: z, phoneNumber: Y, name: V, password: J, tenantName: te, lastName: re } = H;
1273
+ const { email: z, phoneNumber: Y, name: j, password: J, tenantName: te, lastName: re } = H;
1252
1274
  if (!z && !Y)
1253
1275
  throw new Error("Either email or phoneNumber is required");
1254
- if (!V || !J || !te)
1276
+ if (!j || !J || !te)
1255
1277
  throw new Error("Name, password, and tenantName are required");
1256
1278
  return await S.signupTenantAdmin({
1257
1279
  email: z,
1258
1280
  phoneNumber: Y,
1259
- name: V,
1281
+ name: j,
1260
1282
  password: J,
1261
1283
  tenantName: te,
1262
1284
  appId: t,
1263
1285
  lastName: re
1264
1286
  });
1265
1287
  }, nt = async (H) => {
1266
- const { currentPassword: z, newPassword: Y } = H, V = await l.getAuthHeaders();
1267
- await S.changePassword({ currentPassword: z, newPassword: Y }, V);
1288
+ const { currentPassword: z, newPassword: Y } = H, j = await l.getAuthHeaders();
1289
+ await S.changePassword({ currentPassword: z, newPassword: Y }, j);
1268
1290
  }, st = async (H) => {
1269
- const { email: z, tenantId: Y } = H, V = Y ?? (i == null ? void 0 : i.id);
1270
- if (!V)
1291
+ const { email: z, tenantId: Y } = H, j = Y ?? (i == null ? void 0 : i.id);
1292
+ if (!j)
1271
1293
  throw new Error("tenantId is required for password reset");
1272
- await S.requestPasswordReset({ email: z, tenantId: V });
1294
+ await S.requestPasswordReset({ email: z, tenantId: j });
1273
1295
  }, it = async (H) => {
1274
1296
  const { token: z, newPassword: Y } = H;
1275
1297
  await S.confirmPasswordReset({ token: z, newPassword: Y });
1276
1298
  }, ot = async (H) => {
1277
- const { email: z, frontendUrl: Y, name: V, lastName: J, tenantId: te } = H, re = te ?? (i == null ? void 0 : i.id);
1299
+ const { email: z, frontendUrl: Y, name: j, lastName: J, tenantId: te } = H, re = te ?? (i == null ? void 0 : i.id);
1278
1300
  if (!re)
1279
1301
  throw new Error("tenantId is required for magic link authentication");
1280
1302
  return await S.sendMagicLink({
1281
1303
  email: z,
1282
1304
  tenantId: re,
1283
1305
  frontendUrl: Y,
1284
- name: V,
1306
+ name: j,
1285
1307
  lastName: J,
1286
1308
  appId: t
1287
1309
  });
1288
1310
  }, at = async (H) => {
1289
- const { token: z, email: Y, tenantSlug: V } = H;
1311
+ const { token: z, email: Y, tenantSlug: j } = H;
1290
1312
  let J = i == null ? void 0 : i.id, te = o, re = l;
1291
- V && (J = (await new be(C, t).getPublicTenantInfo(V)).id, te = V);
1313
+ j && (J = (await new ve(C, t).getPublicTenantInfo(j)).id, te = j);
1292
1314
  const ne = await S.verifyMagicLink({
1293
1315
  token: z,
1294
1316
  email: Y,
1295
1317
  appId: t,
1296
1318
  tenantId: J
1297
- }), K = V && V !== o;
1298
- if (K && (re = new we({
1319
+ }), K = j && j !== o;
1320
+ if (K && (re = new Se({
1299
1321
  tenantSlug: te,
1300
1322
  baseUrl: r
1301
1323
  })), re.setTokens({
@@ -1305,9 +1327,9 @@ function Tr({ config: n = {}, children: e }) {
1305
1327
  }), ne.user) {
1306
1328
  re.setUser(ne.user), p(ne.user);
1307
1329
  try {
1308
- await G();
1309
- } catch (ye) {
1310
- console.warn("Failed to load complete user data after magic link login:", ye);
1330
+ await V();
1331
+ } catch (be) {
1332
+ console.warn("Failed to load complete user data after magic link login:", be);
1311
1333
  }
1312
1334
  }
1313
1335
  return K && te && te !== o && a(te, {
@@ -1339,7 +1361,7 @@ function Tr({ config: n = {}, children: e }) {
1339
1361
  l.setTokens(H);
1340
1362
  }, ut = () => l.hasValidSession(), ht = () => {
1341
1363
  l.clearSession(), p(null), E(null);
1342
- }, pt = async () => {
1364
+ }, ft = async () => {
1343
1365
  if (t)
1344
1366
  try {
1345
1367
  c(!0);
@@ -1350,8 +1372,8 @@ function Tr({ config: n = {}, children: e }) {
1350
1372
  } finally {
1351
1373
  c(!1);
1352
1374
  }
1353
- }, ft = async () => {
1354
- await pt();
1375
+ }, pt = async () => {
1376
+ await ft();
1355
1377
  }, Re = (H) => {
1356
1378
  if (!Q || Q.length === 0)
1357
1379
  return !1;
@@ -1365,8 +1387,8 @@ function Tr({ config: n = {}, children: e }) {
1365
1387
  isAuthenticated: O,
1366
1388
  sessionManager: l,
1367
1389
  authenticatedHttpService: C,
1368
- login: Ae,
1369
- signup: Pe,
1390
+ login: fe,
1391
+ signup: pe,
1370
1392
  signupTenantAdmin: rt,
1371
1393
  sendMagicLink: ot,
1372
1394
  verifyMagicLink: at,
@@ -1381,11 +1403,11 @@ function Tr({ config: n = {}, children: e }) {
1381
1403
  currentUser: I,
1382
1404
  isUserLoading: x,
1383
1405
  userError: F,
1384
- loadUserData: G,
1406
+ loadUserData: V,
1385
1407
  refreshUser: he,
1386
1408
  isAuthInitializing: !h,
1387
1409
  isAuthReady: h,
1388
- userRole: j,
1410
+ userRole: G,
1389
1411
  userPermissions: Q,
1390
1412
  availableRoles: f,
1391
1413
  rolesLoading: w,
@@ -1393,21 +1415,21 @@ function Tr({ config: n = {}, children: e }) {
1393
1415
  hasAnyPermission: (H) => H.some((z) => Re(z)),
1394
1416
  hasAllPermissions: (H) => H.every((z) => Re(z)),
1395
1417
  getUserPermissionStrings: () => Q || [],
1396
- refreshRoles: ft,
1418
+ refreshRoles: pt,
1397
1419
  // RFC-004: Multi-tenant user membership
1398
1420
  userTenants: k,
1399
1421
  hasTenantContext: M,
1400
1422
  switchToTenant: async (H, z) => {
1401
- const { redirectPath: Y } = z || {}, V = l.getTokens();
1402
- if (!(V != null && V.refreshToken))
1423
+ const { redirectPath: Y } = z || {}, j = l.getTokens();
1424
+ if (!(j != null && j.refreshToken))
1403
1425
  throw new Error("No refresh token available for tenant switch");
1404
1426
  const J = await S.switchTenant({
1405
- refreshToken: V.refreshToken,
1427
+ refreshToken: j.refreshToken,
1406
1428
  tenantId: H
1407
1429
  });
1408
1430
  l.setTokens({
1409
1431
  accessToken: J.accessToken,
1410
- refreshToken: V.refreshToken,
1432
+ refreshToken: j.refreshToken,
1411
1433
  // Keep the same refresh token
1412
1434
  expiresIn: J.expiresIn
1413
1435
  }), p(J.user), l.setUser(J.user), L(!0);
@@ -1415,7 +1437,7 @@ function Tr({ config: n = {}, children: e }) {
1415
1437
  te && a(te.subdomain, {
1416
1438
  tokens: {
1417
1439
  accessToken: J.accessToken,
1418
- refreshToken: V.refreshToken,
1440
+ refreshToken: j.refreshToken,
1419
1441
  expiresIn: J.expiresIn
1420
1442
  },
1421
1443
  redirectPath: Y
@@ -1449,7 +1471,7 @@ function Tr({ config: n = {}, children: e }) {
1449
1471
  k,
1450
1472
  M,
1451
1473
  h,
1452
- j,
1474
+ G,
1453
1475
  Q,
1454
1476
  A,
1455
1477
  q
@@ -1458,8 +1480,8 @@ function Tr({ config: n = {}, children: e }) {
1458
1480
  !n.initialRoles && t && (async () => {
1459
1481
  try {
1460
1482
  c(!0);
1461
- const he = new ce(r), Ae = new _e(he), { roles: Pe } = await Ae.getRolesByApp(t);
1462
- g(Pe);
1483
+ const he = new ce(r), fe = new _e(he), { roles: pe } = await fe.getRolesByApp(t);
1484
+ g(pe);
1463
1485
  } catch (he) {
1464
1486
  console.error("Failed to fetch roles:", he);
1465
1487
  } finally {
@@ -1469,14 +1491,21 @@ function Tr({ config: n = {}, children: e }) {
1469
1491
  }, [t, r, n.initialRoles]);
1470
1492
  const [B, X] = T(!1);
1471
1493
  return ee(() => {
1472
- B || (X(!0), D.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), Rt(), U(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), W.loadUserData().catch((G) => {
1473
- console.error("[AuthProvider] Failed to load user data:", G);
1494
+ B || (X(!0), D.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), Rt(), U(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), W.loadUserData().catch((V) => {
1495
+ console.error("[AuthProvider] Failed to load user data:", V);
1474
1496
  }).finally(() => {
1475
1497
  console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), U(!1);
1476
1498
  })));
1477
1499
  }, [W, B]), ee(() => {
1478
- const G = l.getUser();
1479
- G && l.hasValidSession() ? (p(G), $(!1)) : l.hasValidSession() || $(!1);
1500
+ let V = !1;
1501
+ return (async () => {
1502
+ var pe;
1503
+ if (!l.hasValidSession() && ((pe = l.getTokens()) != null && pe.refreshToken) && await l.waitForPendingRefresh(), V) return;
1504
+ const fe = l.getUser();
1505
+ fe && l.hasValidSession() ? (p(fe), $(!1)) : l.hasValidSession() || $(!1);
1506
+ })(), () => {
1507
+ V = !0;
1508
+ };
1480
1509
  }, [l]), ee(() => {
1481
1510
  B && (D.current.urlTokens || (!I && !x && l.hasValidSession() ? (console.log("[AuthProvider] Auto-loading user data..."), W.loadUserData().catch(() => {
1482
1511
  }).finally(() => {
@@ -1485,11 +1514,11 @@ function Tr({ config: n = {}, children: e }) {
1485
1514
  }, [I, x, W, l, B]), ee(() => {
1486
1515
  if (!l.hasValidSession() || !I)
1487
1516
  return;
1488
- const G = setInterval(() => {
1517
+ const V = setInterval(() => {
1489
1518
  W.loadUserData().catch(() => {
1490
1519
  });
1491
1520
  }, q);
1492
- return () => clearInterval(G);
1521
+ return () => clearInterval(V);
1493
1522
  }, [l, I, W, q]), /* @__PURE__ */ s(Ne.Provider, { value: W, children: e });
1494
1523
  }
1495
1524
  function ue() {
@@ -1581,9 +1610,9 @@ class It {
1581
1610
  })).data;
1582
1611
  }
1583
1612
  }
1584
- const Ue = fe(null);
1613
+ const Ue = me(null);
1585
1614
  function kr({ config: n = {}, children: e }) {
1586
- const t = Ze(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [f, g] = T([]), [w, c] = T(!1), [I, p] = T(null), [x, R] = T(!1), F = Z(() => {
1615
+ const t = Ze(), r = Pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [f, g] = T([]), [w, c] = T(!1), [I, p] = T(null), [x, R] = T(!1), F = Z(() => {
1587
1616
  const u = new ce(i);
1588
1617
  return new It(u);
1589
1618
  }, [i]), E = async () => {
@@ -1706,9 +1735,9 @@ class Mt {
1706
1735
  )).data;
1707
1736
  }
1708
1737
  }
1709
- const $e = fe(void 0);
1738
+ const $e = me(void 0);
1710
1739
  function xr({ config: n = {}, children: e }) {
1711
- const t = Ze(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, f] = T(null), [g, w] = T(!1), [c, I] = T(null), [p, x] = T(!1), R = Z(() => {
1740
+ const t = Ze(), r = Pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, f] = T(null), [g, w] = T(!1), [c, I] = T(null), [p, x] = T(!1), R = Z(() => {
1712
1741
  const A = new ce(i);
1713
1742
  return new Mt(A);
1714
1743
  }, [i]), F = async () => {
@@ -1792,7 +1821,7 @@ const He = {
1792
1821
  admin: { tenant: "required", auth: "required", userType: ae.TENANT_ADMIN },
1793
1822
  // Fully open
1794
1823
  open: { tenant: "optional", auth: "optional" }
1795
- }, Be = fe(null);
1824
+ }, Be = me(null);
1796
1825
  function Ar({ config: n = {}, children: e }) {
1797
1826
  const t = Z(() => {
1798
1827
  const r = {
@@ -2035,7 +2064,7 @@ function Ir({
2035
2064
  requireAllPermissions: i = !1,
2036
2065
  fallback: o
2037
2066
  }) {
2038
- const { hasValidSession: a, sessionManager: f, hasPermission: g, hasAnyPermission: w, hasAllPermissions: c } = ue(), I = ke();
2067
+ const { hasValidSession: a, sessionManager: f, hasPermission: g, hasAnyPermission: w, hasAllPermissions: c } = ue(), I = Ae();
2039
2068
  if (ee(() => {
2040
2069
  process.env.NODE_ENV === "development" && console.warn(
2041
2070
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
@@ -2043,11 +2072,11 @@ function Ir({
2043
2072
  }, []), !a())
2044
2073
  return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
2045
2074
  /* @__PURE__ */ s(Nt, { redirectPath: e }),
2046
- /* @__PURE__ */ s(Se, { to: e, state: { from: I.pathname }, replace: !0 })
2075
+ /* @__PURE__ */ s(Te, { to: e, state: { from: I.pathname }, replace: !0 })
2047
2076
  ] });
2048
2077
  const p = f.getUser();
2049
2078
  if (!p)
2050
- return /* @__PURE__ */ s(Se, { to: e, state: { from: I.pathname }, replace: !0 });
2079
+ return /* @__PURE__ */ s(Te, { to: e, state: { from: I.pathname }, replace: !0 });
2051
2080
  if (t && !Ct(p.userType, t))
2052
2081
  return /* @__PURE__ */ s(
2053
2082
  Ge,
@@ -2100,14 +2129,14 @@ const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
2100
2129
  }
2101
2130
  );
2102
2131
  function Er({ children: n, redirectTo: e = "/", fallback: t }) {
2103
- const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2132
+ const { tenant: r, isLoading: i, error: o } = we(), a = Ae();
2104
2133
  return ee(() => {
2105
2134
  process.env.NODE_ENV === "development" && console.warn(
2106
2135
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
2107
2136
  );
2108
2137
  }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2109
2138
  /* @__PURE__ */ s(Ut, { redirectPath: e }),
2110
- /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2139
+ /* @__PURE__ */ s(Te, { to: e, state: { from: a.pathname }, replace: !0 })
2111
2140
  ] });
2112
2141
  }
2113
2142
  const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
@@ -2148,14 +2177,14 @@ const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2148
2177
  }
2149
2178
  );
2150
2179
  function Mr({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2151
- const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2180
+ const { tenant: r, isLoading: i, error: o } = we(), a = Ae();
2152
2181
  return ee(() => {
2153
2182
  process.env.NODE_ENV === "development" && console.warn(
2154
2183
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
2155
2184
  );
2156
2185
  }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2157
2186
  /* @__PURE__ */ s($t, { redirectPath: e }),
2158
- /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2187
+ /* @__PURE__ */ s(Te, { to: e, state: { from: a.pathname }, replace: !0 })
2159
2188
  ] }) : /* @__PURE__ */ s(_, { children: n });
2160
2189
  }
2161
2190
  function Ht(n, e) {
@@ -2195,7 +2224,7 @@ const de = ({
2195
2224
  loadingFallback: c,
2196
2225
  accessDeniedFallback: I
2197
2226
  }) => {
2198
- const p = ke(), { isAuthenticated: x, isAuthInitializing: R, currentUser: F, userPermissions: E } = ue(), { tenant: A, isTenantLoading: u } = ge(), k = Ft(), m = Z(() => {
2227
+ const p = Ae(), { isAuthenticated: x, isAuthInitializing: R, currentUser: F, userPermissions: E } = ue(), { tenant: A, isTenantLoading: u } = ye(), k = Ft(), m = Z(() => {
2199
2228
  if (e)
2200
2229
  return k.presets[e];
2201
2230
  }, [e, k.presets]), M = Z(
@@ -2262,7 +2291,7 @@ const de = ({
2262
2291
  k.returnToParam,
2263
2292
  k.returnToStorage
2264
2293
  );
2265
- return /* @__PURE__ */ s(Se, { to: N, replace: !0 });
2294
+ return /* @__PURE__ */ s(Te, { to: N, replace: !0 });
2266
2295
  }
2267
2296
  return /* @__PURE__ */ s(_, { children: n });
2268
2297
  }, Lr = (n) => /* @__PURE__ */ s(de, { tenant: "required", ...n }), Fr = (n) => /* @__PURE__ */ s(de, { tenant: "forbidden", ...n }), Dr = (n) => /* @__PURE__ */ s(de, { auth: "required", ...n }), Nr = (n) => /* @__PURE__ */ s(de, { auth: "forbidden", ...n }), Cr = (n) => /* @__PURE__ */ s(de, { auth: "required", userType: ae.TENANT_ADMIN, ...n }), Ur = (n) => /* @__PURE__ */ s(de, { auth: "required", userType: ae.USER, ...n }), $r = (n) => /* @__PURE__ */ s(de, { tenant: "optional", auth: "optional", ...n }), Hr = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "required", ...n }), Br = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "optional", ...n }), qr = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "forbidden", ...n }), _t = () => /* @__PURE__ */ d(
@@ -2517,7 +2546,7 @@ function _r({
2517
2546
  showMagicLinkOption: c = !0,
2518
2547
  className: I
2519
2548
  }) {
2520
- const [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T({}), { login: P } = ue(), { tenant: U } = me(), l = { ...Qt, ...n }, N = { ...Kt, ...e }, $ = { ...Gt, ...t }, h = () => {
2549
+ const [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T({}), { login: P } = ue(), { tenant: U } = we(), l = { ...Qt, ...n }, N = { ...Kt, ...e }, $ = { ...Gt, ...t }, h = () => {
2521
2550
  const y = {};
2522
2551
  return p.trim() || (y.username = !0), R.trim() || (y.password = !0), D(y), Object.keys(y).length === 0;
2523
2552
  }, C = async (y) => {
@@ -2535,8 +2564,8 @@ function _r({
2535
2564
  });
2536
2565
  r == null || r(v);
2537
2566
  } catch (v) {
2538
- const j = v.message || l.errorMessage;
2539
- M(j), i == null || i(j);
2567
+ const G = v.message || l.errorMessage;
2568
+ M(G), i == null || i(G);
2540
2569
  } finally {
2541
2570
  k(!1);
2542
2571
  }
@@ -2766,11 +2795,11 @@ function Wr({
2766
2795
  showMagicLinkOption: g = !0,
2767
2796
  className: w
2768
2797
  }) {
2769
- const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(""), [u, k] = T(""), [m, M] = T(""), [L, D] = T(""), [P, U] = T(!1), [l, N] = T(""), [$, h] = T({}), { signup: C, signupTenantAdmin: S } = ue(), { tenant: b } = me(), y = { ...Zt, ...n }, v = { ...Jt, ...e }, j = () => {
2798
+ const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(""), [u, k] = T(""), [m, M] = T(""), [L, D] = T(""), [P, U] = T(!1), [l, N] = T(""), [$, h] = T({}), { signup: C, signupTenantAdmin: S } = ue(), { tenant: b } = we(), y = { ...Zt, ...n }, v = { ...Jt, ...e }, G = () => {
2770
2799
  const B = {};
2771
2800
  return c.trim() || (B.name = !0), !R.trim() && !E.trim() && (B.email = !0, B.phoneNumber = !0), u.trim() || (B.password = !0), m.trim() || (B.confirmPassword = !0), t === "tenant" && !L.trim() && (B.tenantName = !0), h(B), Object.keys(B).length === 0;
2772
2801
  }, Q = async (B) => {
2773
- if (B.preventDefault(), !!j()) {
2802
+ if (B.preventDefault(), !!G()) {
2774
2803
  if (u !== m) {
2775
2804
  N(y.passwordMismatchError), h({ confirmPassword: !0 });
2776
2805
  return;
@@ -2798,8 +2827,8 @@ function Wr({
2798
2827
  lastName: p || void 0
2799
2828
  }), r == null || r(X);
2800
2829
  } catch (X) {
2801
- const G = X.message || y.errorMessage;
2802
- N(G), i == null || i(G);
2830
+ const V = X.message || y.errorMessage;
2831
+ N(V), i == null || i(V);
2803
2832
  } finally {
2804
2833
  U(!1);
2805
2834
  }
@@ -3106,7 +3135,7 @@ function Vr({
3106
3135
  verifyToken: g,
3107
3136
  frontendUrl: w
3108
3137
  }) {
3109
- const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T(""), [P, U] = T({}), [l, N] = T(!1), { sendMagicLink: $, verifyMagicLink: h } = ue(), { tenant: C } = me(), S = { ...Yt, ...n }, b = { ...Xt, ...e };
3138
+ const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T(""), [P, U] = T({}), [l, N] = T(!1), { sendMagicLink: $, verifyMagicLink: h } = ue(), { tenant: C } = we(), S = { ...Yt, ...n }, b = { ...Xt, ...e };
3110
3139
  ee(() => {
3111
3140
  g && y(g);
3112
3141
  }, [g]);
@@ -3132,7 +3161,7 @@ function Vr({
3132
3161
  }, v = () => {
3133
3162
  const q = {};
3134
3163
  return c.trim() || (q.email = !0), l && !p.trim() && (q.name = !0), U(q), Object.keys(q).length === 0;
3135
- }, j = async (q) => {
3164
+ }, G = async (q) => {
3136
3165
  if (q.preventDefault(), !!v()) {
3137
3166
  if (!(C != null && C.id)) {
3138
3167
  M("Tenant not found");
@@ -3169,7 +3198,7 @@ function Vr({
3169
3198
  ] }) : /* @__PURE__ */ d("div", { className: f, style: b.container, children: [
3170
3199
  /* @__PURE__ */ s("h2", { style: b.title, children: S.title }),
3171
3200
  /* @__PURE__ */ s("p", { style: b.description, children: S.description }),
3172
- /* @__PURE__ */ d("form", { onSubmit: j, style: b.form, children: [
3201
+ /* @__PURE__ */ d("form", { onSubmit: G, style: b.form, children: [
3173
3202
  /* @__PURE__ */ d("div", { style: b.fieldGroup, children: [
3174
3203
  /* @__PURE__ */ s("label", { style: b.label, children: S.emailLabel }),
3175
3204
  /* @__PURE__ */ s(
@@ -3658,7 +3687,7 @@ function Gr({
3658
3687
  onModeChange: f,
3659
3688
  className: g
3660
3689
  }) {
3661
- const [w, c] = T(""), [I, p] = T(r), [x, R] = T(""), [F, E] = T(""), [A, u] = T(!1), [k, m] = T(""), [M, L] = T(""), [D, P] = T({}), { requestPasswordReset: U, confirmPasswordReset: l } = ue(), { tenant: N } = me(), $ = { ...ir, ...n }, h = { ...or, ...e }, C = () => {
3690
+ const [w, c] = T(""), [I, p] = T(r), [x, R] = T(""), [F, E] = T(""), [A, u] = T(!1), [k, m] = T(""), [M, L] = T(""), [D, P] = T({}), { requestPasswordReset: U, confirmPasswordReset: l } = ue(), { tenant: N } = we(), $ = { ...ir, ...n }, h = { ...or, ...e }, C = () => {
3662
3691
  const O = {};
3663
3692
  return w.trim() || (O.email = !0), P(O), Object.keys(O).length === 0;
3664
3693
  }, S = () => {
@@ -3699,7 +3728,7 @@ function Gr({
3699
3728
  }, v = (O) => ({
3700
3729
  ...h.input,
3701
3730
  ...D[O] ? h.inputError : {}
3702
- }), j = () => ({
3731
+ }), G = () => ({
3703
3732
  ...h.button,
3704
3733
  ...A ? h.buttonLoading : {}
3705
3734
  });
@@ -3763,7 +3792,7 @@ function Gr({
3763
3792
  type: "submit",
3764
3793
  disabled: !O || A,
3765
3794
  style: {
3766
- ...j(),
3795
+ ...G(),
3767
3796
  ...!O || A ? h.buttonDisabled : {}
3768
3797
  },
3769
3798
  children: A ? $.resetLoadingText : $.resetSubmitButton
@@ -3808,7 +3837,7 @@ function Gr({
3808
3837
  type: "submit",
3809
3838
  disabled: !Q || A,
3810
3839
  style: {
3811
- ...j(),
3840
+ ...G(),
3812
3841
  ...!Q || A ? h.buttonDisabled : {}
3813
3842
  },
3814
3843
  children: A ? $.loadingText : $.submitButton
@@ -3878,7 +3907,7 @@ function Qr({
3878
3907
  errorFallback: t,
3879
3908
  requireTenant: r = !0
3880
3909
  }) {
3881
- const { isAppLoading: i, appError: o, retryApp: a } = ve(), f = xe(), g = Ce(), w = Je(), c = Ye(), I = (f == null ? void 0 : f.isTenantLoading) ?? !1, p = (f == null ? void 0 : f.tenantError) ?? null, x = (f == null ? void 0 : f.tenantSlug) ?? null, R = (f == null ? void 0 : f.retryTenant) ?? (() => {
3910
+ const { isAppLoading: i, appError: o, retryApp: a } = ke(), f = Pe(), g = Ce(), w = Je(), c = Ye(), I = (f == null ? void 0 : f.isTenantLoading) ?? !1, p = (f == null ? void 0 : f.tenantError) ?? null, x = (f == null ? void 0 : f.tenantSlug) ?? null, R = (f == null ? void 0 : f.retryTenant) ?? (() => {
3882
3911
  }), F = (g == null ? void 0 : g.isAuthReady) ?? !0, E = (w == null ? void 0 : w.isReady) ?? !0, A = (c == null ? void 0 : c.isReady) ?? !0, u = r && f && x, L = i || u && I || g && !F || w && !E || c && !A, D = o || (u ? p : null), P = () => {
3883
3912
  o && a(), p && f && R();
3884
3913
  };
@@ -3891,7 +3920,7 @@ function Qr({
3891
3920
  return /* @__PURE__ */ s(_, { children: n });
3892
3921
  }
3893
3922
  function Kr(n = !0) {
3894
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = ve(), o = xe(), a = Ce(), f = Je(), g = Ye(), w = (o == null ? void 0 : o.isTenantLoading) ?? !1, c = (o == null ? void 0 : o.tenantError) ?? null, I = (o == null ? void 0 : o.tenant) ?? null, p = (o == null ? void 0 : o.tenantSlug) ?? null, x = (o == null ? void 0 : o.retryTenant) ?? (() => {
3923
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = ke(), o = Pe(), a = Ce(), f = Je(), g = Ye(), w = (o == null ? void 0 : o.isTenantLoading) ?? !1, c = (o == null ? void 0 : o.tenantError) ?? null, I = (o == null ? void 0 : o.tenant) ?? null, p = (o == null ? void 0 : o.tenantSlug) ?? null, x = (o == null ? void 0 : o.retryTenant) ?? (() => {
3895
3924
  }), R = (a == null ? void 0 : a.isAuthReady) ?? !0, F = (f == null ? void 0 : f.isReady) ?? !0, E = (g == null ? void 0 : g.isReady) ?? !0, A = n && o && p, M = e || A && w || a && !R || f && !F || g && !E, L = t || (A ? c : null);
3896
3925
  return {
3897
3926
  isLoading: M,
@@ -4260,7 +4289,7 @@ function tn(n = {}) {
4260
4289
  zoneRoots: e = {},
4261
4290
  returnToParam: t = tt,
4262
4291
  returnToStorage: r = "url"
4263
- } = n, i = gt(), [o, a] = mt(), { isAuthenticated: f, currentUser: g } = ue(), { tenant: w } = ge(), c = Z(() => ({ ...He, ...e }), [e]), I = !!w, p = g == null ? void 0 : g.userType, x = Z(() => {
4292
+ } = n, i = gt(), [o, a] = mt(), { isAuthenticated: f, currentUser: g } = ue(), { tenant: w } = ye(), c = Z(() => ({ ...He, ...e }), [e]), I = !!w, p = g == null ? void 0 : g.userType, x = Z(() => {
4264
4293
  switch (r) {
4265
4294
  case "url":
4266
4295
  return o.get(t);
@@ -4271,7 +4300,7 @@ function tn(n = {}) {
4271
4300
  default:
4272
4301
  return null;
4273
4302
  }
4274
- }, [r, o, t]), R = se(() => {
4303
+ }, [r, o, t]), R = ie(() => {
4275
4304
  switch (r) {
4276
4305
  case "url": {
4277
4306
  const u = new URLSearchParams(o);
@@ -4285,7 +4314,7 @@ function tn(n = {}) {
4285
4314
  localStorage.removeItem(Le);
4286
4315
  break;
4287
4316
  }
4288
- }, [r, o, t, a]), F = se(
4317
+ }, [r, o, t, a]), F = ie(
4289
4318
  (u) => {
4290
4319
  switch (r) {
4291
4320
  case "url": {
@@ -4302,13 +4331,13 @@ function tn(n = {}) {
4302
4331
  }
4303
4332
  },
4304
4333
  [r, o, t, a]
4305
- ), E = se(
4334
+ ), E = ie(
4306
4335
  (u) => {
4307
4336
  const k = c[u] || c.default;
4308
4337
  i(k);
4309
4338
  },
4310
4339
  [i, c]
4311
- ), A = se(() => I ? f ? p === ae.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : f ? p === ae.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [I, f, p, c]);
4340
+ ), A = ie(() => I ? f ? p === ae.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : f ? p === ae.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [I, f, p, c]);
4312
4341
  return {
4313
4342
  returnToUrl: x,
4314
4343
  clearReturnTo: R,
@@ -4352,14 +4381,14 @@ export {
4352
4381
  Fr as PublicZone,
4353
4382
  _e as RoleApiService,
4354
4383
  Ar as RoutingProvider,
4355
- ie as SessionExpiredError,
4356
- we as SessionManager,
4384
+ se as SessionExpiredError,
4385
+ Se as SessionManager,
4357
4386
  Wr as SignupForm,
4358
4387
  Mt as SubscriptionApiService,
4359
4388
  Or as SubscriptionGuard,
4360
4389
  Yr as SubscriptionPlanApiService,
4361
4390
  xr as SubscriptionProvider,
4362
- be as TenantApiService,
4391
+ ve as TenantApiService,
4363
4392
  Hr as TenantAuthenticatedZone,
4364
4393
  qr as TenantGuestZone,
4365
4394
  Br as TenantOpenZone,
@@ -4375,7 +4404,7 @@ export {
4375
4404
  de as ZoneRoute,
4376
4405
  rn as buildRedirectUrl,
4377
4406
  wr as useApi,
4378
- ve as useApp,
4407
+ ke as useApp,
4379
4408
  Kr as useAppLoaderState,
4380
4409
  ue as useAuth,
4381
4410
  Et as useFeatureFlags,
@@ -4383,9 +4412,9 @@ export {
4383
4412
  Ft as useRoutingOptional,
4384
4413
  vr as useSettings,
4385
4414
  Lt as useSubscription,
4386
- ge as useTenant,
4387
- me as useTenantInfo,
4388
- xe as useTenantOptional,
4415
+ ye as useTenant,
4416
+ we as useTenantInfo,
4417
+ Pe as useTenantOptional,
4389
4418
  Sr as useTenantSettings,
4390
4419
  tn as useZoneNavigation
4391
4420
  };