@nibssplc/cams-sdk-react 1.0.0-rc.88 → 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
@@ -461,7 +461,7 @@ function useCAMSMSALAuth(options) {
461
461
  }
462
462
  }, [accessToken, account, instance, options.storageKey]);
463
463
  var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
464
- var response, mfaConfig, authenticator, userConfig, camsError, err_1, camsError_1, camsError;
464
+ var response, authenticator, userConfig, camsError, err_1, camsError_1, camsError;
465
465
  var _a;
466
466
  return __generator$1(this, function (_b) {
467
467
  switch (_b.label) {
@@ -476,33 +476,28 @@ function useCAMSMSALAuth(options) {
476
476
  _b.trys.push([1, 4, , 5]);
477
477
  return [4 /*yield*/, instance.loginPopup({
478
478
  scopes: scopes,
479
- prompt: prompt || "select_account",
479
+ prompt: prompt || "login",
480
480
  })];
481
481
  case 2:
482
482
  response = _b.sent();
483
- mfaConfig = {
484
- accessToken: response.accessToken,
485
- idToken: response.idToken,
486
- provider: "MSAL",
487
- APIAuthEndpoint: ValidateUserEndpoint,
488
- };
489
483
  authenticator = new CAMSMFAAuthenticator();
490
484
  setIsFetchingMFAConfig(true);
491
- 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
+ })];
492
491
  case 3:
493
492
  userConfig = _b.sent();
494
493
  setIsFetchingMFAConfig(false);
495
- console.log("CAMS MFA Authenticator initialized:", {
496
- mfaConfig: mfaConfig,
494
+ Logger.info("CAMS MFA Authenticator initialized. MSAL User Auth is Completed...", {
497
495
  userConfig: userConfig,
496
+ storageKey: storageKey,
497
+ email: userConfig.userInfo.email,
498
498
  });
499
- Logger.info("MSAL User Auth is Completed");
500
499
  // Don't persist as authenticated until MFA is complete
501
500
  if (userConfig.isValid && userConfig.userInfo.email) {
502
- Logger.info("MSAL User Auth is Completed...", {
503
- storageKey: storageKey,
504
- email: userConfig.userInfo.email,
505
- });
506
501
  setAccessToken(response.accessToken);
507
502
  setIdToken(response.idToken);
508
503
  localStorage.setItem(storageKey, JSON.stringify({
@@ -617,7 +612,7 @@ function useCAMSMSALAuth(options) {
617
612
  setRequiresMFA(false);
618
613
  if (typeof window !== "undefined") {
619
614
  localStorage.removeItem(storageKey);
620
- // deleteCookie("CAMS-MSAL-AUTH-SDK-PROFILE");
615
+ deleteCookie(storageKey + "-PROFILE");
621
616
  }
622
617
  return [4 /*yield*/, instance.logoutRedirect()];
623
618
  case 1:
@@ -1837,8 +1832,6 @@ var MFAGate = function (_a) {
1837
1832
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1838
1833
  }
1839
1834
  }
1840
- // Force state update after MFA completion
1841
- setAuthState("Authenticated");
1842
1835
  }
1843
1836
  else if (!success) {
1844
1837
  Logger.error("MFA authentication failed", { context: context || null });
@@ -1863,59 +1856,21 @@ var MFAGate = function (_a) {
1863
1856
  });
1864
1857
  }); }, [context, onAuthError]);
1865
1858
  useEffect(function () {
1866
- console.log("Auth evaluation triggered:", {
1867
- isLoading: context.isLoading,
1868
- isAuthenticated: context.isAuthenticated,
1869
- contextRequiresMFA: contextRequiresMFA,
1870
- contextAccessToken: !!contextAccessToken,
1871
- requiresMFA: requiresMFA,
1872
- });
1873
1859
  if (context.isLoading) {
1874
1860
  setAuthState("Loading");
1875
1861
  return;
1876
1862
  }
1877
- // Check if user has accessToken (MSAL authenticated)
1878
1863
  if (!contextAccessToken) {
1879
1864
  setAuthState("Unauthenticated");
1880
1865
  return;
1881
1866
  }
1882
- // User has accessToken, determine if MFA is required
1883
1867
  var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
1884
- console.log("MFA decision:", {
1885
- shouldRequireMFA: shouldRequireMFA,
1886
- hasAccessToken: !!contextAccessToken,
1887
- finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
1888
- });
1889
- if (shouldRequireMFA) {
1890
- setAuthState("MFA_Required");
1891
- }
1892
- else {
1893
- setAuthState("Authenticated");
1894
- }
1895
- }, [
1896
- context.isLoading,
1897
- context.isAuthenticated,
1898
- contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
1899
- contextAccessToken, // And this when accessToken changes
1900
- requiresMFA,
1901
- context.authMode,
1902
- ]);
1903
- // Debug useEffect
1904
- useEffect(function () {
1905
- console.log("Current authState:", authState);
1906
- console.log("Context state:", {
1907
- isLoading: context.isLoading,
1908
- isAuthenticated: context.isAuthenticated,
1909
- authMode: context.authMode,
1910
- requiresMFA: contextRequiresMFA,
1911
- hasAccessToken: !!contextAccessToken,
1912
- });
1868
+ setAuthState(shouldRequireMFA ? "MFA_Required" : "Authenticated");
1913
1869
  }, [
1914
- authState,
1915
1870
  context.isLoading,
1916
- context.isAuthenticated,
1917
1871
  contextRequiresMFA,
1918
1872
  contextAccessToken,
1873
+ requiresMFA,
1919
1874
  ]);
1920
1875
  if (useADLogin && !CredentialsAuthEndpoint)
1921
1876
  return jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });