@nibssplc/cams-sdk-react 1.0.0-rc.68 → 1.0.0-rc.69

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
@@ -412,7 +412,7 @@ var deleteCookie = function (name) {
412
412
 
413
413
  function useCAMSMSALAuth(options) {
414
414
  var _this = this;
415
- var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
415
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, ValidateUserEndpoint = options.ValidateUserEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
416
416
  var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
417
417
  var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
418
418
  var account = useAccount(accounts[0] || {});
@@ -494,7 +494,7 @@ function useCAMSMSALAuth(options) {
494
494
  accessToken: response.accessToken,
495
495
  idToken: response.idToken,
496
496
  provider: "MSAL",
497
- APIAuthEndpoint: MFAEndpoint,
497
+ APIAuthEndpoint: ValidateUserEndpoint,
498
498
  };
499
499
  authenticator = new CAMSMFAAuthenticator();
500
500
  return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
@@ -502,9 +502,9 @@ function useCAMSMSALAuth(options) {
502
502
  userConfig = _b.sent();
503
503
  Logger.debug("MFA Authenticator initialized:", userConfig);
504
504
  console.log("MFA Authenticator initialized:", userConfig);
505
- setRequiresMFA(userConfig.userInfo.isMFAEnabled);
506
505
  // Don't persist as authenticated until MFA is complete
507
- if (typeof window !== "undefined") {
506
+ if (typeof window !== "undefined" && userConfig.isValid) {
507
+ setRequiresMFA(userConfig.userInfo.isMFAEnabled);
508
508
  localStorage.setItem(storageKey, JSON.stringify({
509
509
  isAuthenticated: false,
510
510
  requiresMFA: userConfig.userInfo.isMFAEnabled,
@@ -539,7 +539,15 @@ function useCAMSMSALAuth(options) {
539
539
  case 5: return [2 /*return*/];
540
540
  }
541
541
  });
542
- }); }, [instance, scopes, prompt, appCode, MFAEndpoint, storageKey, inProgress]);
542
+ }); }, [
543
+ instance,
544
+ scopes,
545
+ prompt,
546
+ appCode,
547
+ ValidateUserEndpoint,
548
+ storageKey,
549
+ inProgress,
550
+ ]);
543
551
  var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
544
552
  return __generator$1(this, function (_a) {
545
553
  Logger.info("Completed MFA.. Setting State");
@@ -552,7 +560,11 @@ function useCAMSMSALAuth(options) {
552
560
  accessToken: accessToken,
553
561
  idToken: idToken,
554
562
  }));
555
- setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ state: "AUTH_SUCCESS", role: data.userInfo.role, profile: __assign({}, data) }), activeCookiePeriod);
563
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({
564
+ state: "AUTH_SUCCESS",
565
+ role: data.userInfo.role,
566
+ profile: __assign({}, data),
567
+ }), activeCookiePeriod);
556
568
  setRequiresMFA(false);
557
569
  // Set requiresMFA to false after storage update
558
570
  Logger.debug("MFA completed successfully, storage updated", {
@@ -928,8 +940,8 @@ function CAMSProviderCore(props) {
928
940
  ? __assign(__assign({}, props), { appCode: appCode })
929
941
  : { appCode: "" });
930
942
  var msalAuth = useCAMSMSALAuth(mode === "MSAL"
931
- ? __assign(__assign({}, props), { appCode: appCode })
932
- : { appCode: "" });
943
+ ? __assign(__assign({}, props), { appCode: appCode, ValidateUserEndpoint: props.ValidateUserEndpoint })
944
+ : { appCode: "", ValidateUserEndpoint: "" });
933
945
  var auth = mode === "REGULAR" ? regularAuth : msalAuth;
934
946
  var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
935
947
  var getInitialProfile = function () {
@@ -1559,7 +1571,7 @@ var MFAOptions = function (_a) {
1559
1571
  var _j = useOTPHandler({
1560
1572
  email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || "",
1561
1573
  appCode: context.appCode || "",
1562
- MFAEndpoint: MFAEndpoints.ValidateMFA,
1574
+ MFAEndpoint: MFAEndpoints.ValidateUserMFA,
1563
1575
  onAuthComplete: function (state, data) {
1564
1576
  console.log("Completed Auth. Handling MFA", state);
1565
1577
  if (state) {
@@ -1791,7 +1803,8 @@ var ErrorFallback = function (_a) {
1791
1803
  };
1792
1804
 
1793
1805
  var MFAEndpointsSchema = z$1.object({
1794
- ValidateMFA: z$1.url("MFAEndpoint must be a valid URL"),
1806
+ ValidateUser: z$1.url("ValidateUser Endpoint must be a valid URL"),
1807
+ ValidateUserMFA: z$1.url("ValidateUser MFA Endpoint must be a valid URL"),
1795
1808
  RegisterNewChallenge: z$1.url("MFA RegisterNewChallenge must be a valid URL"),
1796
1809
  RegisterVerify: z$1.url("MFA RegisterVerify must be a valid URL"),
1797
1810
  RetrieveAuthChallenge: z$1.url("MFA RetrieveAuthChallenge must be a valid URL"),