@nibssplc/cams-sdk-react 1.0.0-rc.87 → 1.0.0-rc.89

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.esm.js CHANGED
@@ -458,14 +458,10 @@ function useCAMSMSALAuth(options) {
458
458
  }
459
459
  catch (_b) { }
460
460
  }
461
- else if (account) {
462
- // Storage cleared but MSAL account exists - clear MSAL state
463
- instance.logoutRedirect().catch(function () { });
464
- }
465
461
  }
466
462
  }, [accessToken, account, instance, options.storageKey]);
467
463
  var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
468
- var response, mfaConfig, authenticator, userConfig, camsError, err_1, camsError_1, camsError;
464
+ var response, authenticator, userConfig, camsError, err_1, camsError_1, camsError;
469
465
  var _a;
470
466
  return __generator$1(this, function (_b) {
471
467
  switch (_b.label) {
@@ -484,33 +480,28 @@ function useCAMSMSALAuth(options) {
484
480
  })];
485
481
  case 2:
486
482
  response = _b.sent();
487
- mfaConfig = {
488
- accessToken: response.accessToken,
489
- idToken: response.idToken,
490
- provider: "MSAL",
491
- APIAuthEndpoint: ValidateUserEndpoint,
492
- };
493
483
  authenticator = new CAMSMFAAuthenticator();
494
484
  setIsFetchingMFAConfig(true);
495
- return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
485
+ return [4 /*yield*/, authenticator.GetUserMFAConfig({
486
+ accessToken: response.accessToken,
487
+ idToken: response.idToken,
488
+ provider: "MSAL",
489
+ APIAuthEndpoint: ValidateUserEndpoint,
490
+ })];
496
491
  case 3:
497
492
  userConfig = _b.sent();
498
493
  setIsFetchingMFAConfig(false);
499
- console.log("CAMS MFA Authenticator initialized:", {
500
- mfaConfig: mfaConfig,
494
+ Logger.info("CAMS MFA Authenticator initialized. MSAL User Auth is Completed...", {
501
495
  userConfig: userConfig,
496
+ storageKey: storageKey,
497
+ email: userConfig.userInfo.email,
502
498
  });
503
- Logger.info("MSAL User Auth is Completed");
504
499
  // Don't persist as authenticated until MFA is complete
505
500
  if (userConfig.isValid && userConfig.userInfo.email) {
506
- Logger.info("MSAL User Auth is Completed...", {
507
- storageKey: storageKey,
508
- email: userConfig.userInfo.email,
509
- });
510
501
  setAccessToken(response.accessToken);
511
502
  setIdToken(response.idToken);
512
503
  localStorage.setItem(storageKey, JSON.stringify({
513
- isAuthenticated: false,
504
+ isAuthenticated: !userConfig.userInfo.isMFAEnabled,
514
505
  requiresMFA: userConfig.userInfo.isMFAEnabled,
515
506
  accessToken: response.accessToken,
516
507
  idToken: response.idToken,
@@ -615,17 +606,17 @@ function useCAMSMSALAuth(options) {
615
606
  case 0:
616
607
  _a.trys.push([0, 2, , 3]);
617
608
  Logger.info("Logging User Out");
618
- return [4 /*yield*/, instance.logoutRedirect()];
619
- case 1:
620
- _a.sent();
621
609
  setAccessToken("");
622
610
  setIdToken("");
623
611
  setError(null);
624
612
  setRequiresMFA(false);
625
613
  if (typeof window !== "undefined") {
626
614
  localStorage.removeItem(storageKey);
627
- // deleteCookie("CAMS-MSAL-AUTH-SDK-PROFILE");
615
+ deleteCookie(storageKey + "-PROFILE");
628
616
  }
617
+ return [4 /*yield*/, instance.logoutRedirect()];
618
+ case 1:
619
+ _a.sent();
629
620
  return [3 /*break*/, 3];
630
621
  case 2:
631
622
  err_2 = _a.sent();
@@ -1542,7 +1533,7 @@ var MFAOptions = function (_a) {
1542
1533
  var _f = useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
1543
1534
  var _g = useState(null), authType = _g[0], setAuthType = _g[1];
1544
1535
  var context = useCAMSContext();
1545
- var _h = context.authMode === "MSAL" && "AuthenticatorCode" in context
1536
+ var _h = context.authMode === "MSAL" && "EmailOTP" in context
1546
1537
  ? context
1547
1538
  : { completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1548
1539
  return [2 /*return*/];
@@ -1841,8 +1832,6 @@ var MFAGate = function (_a) {
1841
1832
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1842
1833
  }
1843
1834
  }
1844
- // Force state update after MFA completion
1845
- setAuthState("Authenticated");
1846
1835
  }
1847
1836
  else if (!success) {
1848
1837
  Logger.error("MFA authentication failed", { context: context || null });
@@ -1867,59 +1856,21 @@ var MFAGate = function (_a) {
1867
1856
  });
1868
1857
  }); }, [context, onAuthError]);
1869
1858
  useEffect(function () {
1870
- console.log("Auth evaluation triggered:", {
1871
- isLoading: context.isLoading,
1872
- isAuthenticated: context.isAuthenticated,
1873
- contextRequiresMFA: contextRequiresMFA,
1874
- contextAccessToken: !!contextAccessToken,
1875
- requiresMFA: requiresMFA,
1876
- });
1877
1859
  if (context.isLoading) {
1878
1860
  setAuthState("Loading");
1879
1861
  return;
1880
1862
  }
1881
- // Check if user has accessToken (MSAL authenticated)
1882
1863
  if (!contextAccessToken) {
1883
1864
  setAuthState("Unauthenticated");
1884
1865
  return;
1885
1866
  }
1886
- // User has accessToken, determine if MFA is required
1887
1867
  var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
1888
- console.log("MFA decision:", {
1889
- shouldRequireMFA: shouldRequireMFA,
1890
- hasAccessToken: !!contextAccessToken,
1891
- finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
1892
- });
1893
- if (shouldRequireMFA) {
1894
- setAuthState("MFA_Required");
1895
- }
1896
- else {
1897
- setAuthState("Authenticated");
1898
- }
1868
+ setAuthState(shouldRequireMFA ? "MFA_Required" : "Authenticated");
1899
1869
  }, [
1900
1870
  context.isLoading,
1901
- context.isAuthenticated,
1902
- contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
1903
- contextAccessToken, // And this when accessToken changes
1904
- requiresMFA,
1905
- context.authMode,
1906
- ]);
1907
- // Debug useEffect
1908
- useEffect(function () {
1909
- console.log("Current authState:", authState);
1910
- console.log("Context state:", {
1911
- isLoading: context.isLoading,
1912
- isAuthenticated: context.isAuthenticated,
1913
- authMode: context.authMode,
1914
- requiresMFA: contextRequiresMFA,
1915
- hasAccessToken: !!contextAccessToken,
1916
- });
1917
- }, [
1918
- authState,
1919
- context.isLoading,
1920
- context.isAuthenticated,
1921
1871
  contextRequiresMFA,
1922
1872
  contextAccessToken,
1873
+ requiresMFA,
1923
1874
  ]);
1924
1875
  if (useADLogin && !CredentialsAuthEndpoint)
1925
1876
  return jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });