@spidy092/auth-client 3.2.0 → 3.2.2

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.
@@ -247,7 +247,14 @@ var config = {
247
247
  // Required for local dev with mkcert/self-signed certs where httpOnly cookies
248
248
  // may not work reliably across origins
249
249
  // ⚠️ In true production, set to false and rely on httpOnly cookies
250
- persistRefreshToken: false
250
+ persistRefreshToken: false,
251
+ // ========== CROSS-TAB LOGOUT BROADCAST ==========
252
+ // Name of the BroadcastChannel the SDK posts a {type:'LOGOUT', reason}
253
+ // message on when logout() runs, so sibling tabs of the same app react
254
+ // immediately instead of waiting for a storage event or a validation poll.
255
+ // All company browser clients share one channel so the receiver wiring is
256
+ // identical everywhere. Apps may override per deployment.
257
+ logoutChannelName: "auth_platform_sso_channel"
251
258
  };
252
259
  var RUNTIME_POLICY_DEFAULTS = {
253
260
  tokenRefreshBuffer: 60,
@@ -416,6 +423,19 @@ async function emitAuthDiagnostic(event, outcome, reasonCode, details = {}) {
416
423
 
417
424
  // core.js
418
425
  var callbackProcessed = false;
426
+ var LOGOUT_REQUEST_TIMEOUT_MS = 8e3;
427
+ function broadcastLogoutToTabs(clientKey, reason = "user_logout") {
428
+ try {
429
+ if (typeof BroadcastChannel === "undefined") return;
430
+ const { logoutChannelName } = getConfig();
431
+ if (!logoutChannelName) return;
432
+ const channel = new BroadcastChannel(logoutChannelName);
433
+ channel.postMessage({ type: "LOGOUT", reason, clientKey });
434
+ channel.close();
435
+ } catch (err) {
436
+ console.warn("\u26A0\uFE0F Cross-tab logout broadcast failed (non-fatal):", (err == null ? void 0 : err.message) || err);
437
+ }
438
+ }
419
439
  function login(clientKeyArg, redirectUriArg, options = {}) {
420
440
  resetCallbackState();
421
441
  const {
@@ -486,7 +506,9 @@ async function logout(options = {}) {
486
506
  clearRefreshToken();
487
507
  sessionStorage.removeItem("originalApp");
488
508
  sessionStorage.removeItem("returnUrl");
509
+ broadcastLogoutToTabs(clientKey);
489
510
  try {
511
+ const logoutSignal = typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(LOGOUT_REQUEST_TIMEOUT_MS) : void 0;
490
512
  const response = await fetch(`${authBaseUrl}/logout/${clientKey}`, {
491
513
  method: "POST",
492
514
  credentials: "include",
@@ -495,7 +517,8 @@ async function logout(options = {}) {
495
517
  "Authorization": token ? `Bearer ${token}` : "",
496
518
  "Content-Type": "application/json"
497
519
  },
498
- body: JSON.stringify({ refreshToken: refreshToken2, idToken: idToken2, scope })
520
+ body: JSON.stringify({ refreshToken: refreshToken2, idToken: idToken2, scope }),
521
+ ...logoutSignal ? { signal: logoutSignal } : {}
499
522
  });
500
523
  if (!response.ok) {
501
524
  throw new Error(`Logout failed: ${response.status}`);
@@ -520,6 +543,13 @@ async function logout(options = {}) {
520
543
  clientKey
521
544
  });
522
545
  }
546
+ if (scope === "sso" && authBaseUrl && clientKey) {
547
+ const frontChannelLogoutUrl = new URL(
548
+ `${authBaseUrl.replace(/\/+$/, "")}/logout/${encodeURIComponent(clientKey)}`
549
+ );
550
+ window.location.replace(frontChannelLogoutUrl.toString());
551
+ return;
552
+ }
523
553
  const fallbackUrl = isRouterMode() ? new URL("/login", window.location.origin) : new URL("/login", accountUiUrl);
524
554
  fallbackUrl.searchParams.set("logged_out", "true");
525
555
  fallbackUrl.searchParams.set("client", clientKey);