@nibssplc/cams-sdk-react 1.0.0-rc.15 → 1.0.0-rc.17

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.
@@ -11,6 +11,7 @@ export interface CAMSMSALProviderProps extends UseCAMSMSALAuthOptions {
11
11
  children: React.ReactNode;
12
12
  msalConfig: Configuration;
13
13
  msalInstance?: PublicClientApplication;
14
+ activeCookiePeriod?: number;
14
15
  }
15
16
  export declare function CAMSMSALProvider(props: Readonly<CAMSMSALProviderProps>): import("react/jsx-runtime").JSX.Element;
16
17
  export declare function useCAMSMSALContext(): CAMSMSALContextValue;
@@ -11,6 +11,7 @@ export interface UseCAMSMSALAuthOptions {
11
11
  appCode: string;
12
12
  allowedOrigins?: string[];
13
13
  MFAEndpoint?: string;
14
+ activeCookiePeriod?: number;
14
15
  }
15
16
  export interface UseCAMSMSALAuthReturn {
16
17
  login: () => Promise<void>;
package/dist/index.cjs.js CHANGED
@@ -383,6 +383,7 @@ function useCAMSAuth(options) {
383
383
  }
384
384
 
385
385
  var setCookie$1 = function (name, value, days) {
386
+ if (days === void 0) { days = 1; }
386
387
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
387
388
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
388
389
  };
@@ -492,6 +493,10 @@ function useCAMSMSALAuth(options) {
492
493
  return __generator$1(this, function (_e) {
493
494
  switch (_e.label) {
494
495
  case 0:
496
+ if (inProgress !== msalBrowser.InteractionStatus.None) {
497
+ camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
498
+ return [2 /*return*/];
499
+ }
495
500
  setError(null);
496
501
  _e.label = 1;
497
502
  case 1:
@@ -531,6 +536,11 @@ function useCAMSMSALAuth(options) {
531
536
  return [3 /*break*/, 4];
532
537
  case 3:
533
538
  err_1 = _e.sent();
539
+ // Handle interaction_in_progress error
540
+ if (err_1.errorCode === "interaction_in_progress") {
541
+ camsSdk.Logger.warn("Interaction already in progress, please wait");
542
+ return [2 /*return*/];
543
+ }
534
544
  // Handle user cancellation gracefully
535
545
  if (err_1.errorCode === "user_cancelled") {
536
546
  camsSdk.Logger.error("User cancelled login");
@@ -552,7 +562,7 @@ function useCAMSMSALAuth(options) {
552
562
  case 4: return [2 /*return*/];
553
563
  }
554
564
  });
555
- }); }, [instance, scopes, options]);
565
+ }); }, [instance, scopes, options, inProgress]);
556
566
  var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
557
567
  return __generator$1(this, function (_a) {
558
568
  if (!mfaAuthenticator) {
@@ -568,7 +578,7 @@ function useCAMSMSALAuth(options) {
568
578
  accessToken: accessToken,
569
579
  idToken: idToken,
570
580
  }));
571
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
581
+ setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), options.activeCookiePeriod);
572
582
  setRequiresMFA(false);
573
583
  // Set requiresMFA to false after storage update
574
584
  camsSdk.Logger.debug("MFA completed successfully, storage updated", {
@@ -1237,7 +1247,9 @@ function ProtectedRoute(_a) {
1237
1247
 
1238
1248
  var CAMSMSALContext = React.createContext(null);
1239
1249
  var setCookie = function (name, value, days) {
1250
+ if (days === void 0) { days = 1; }
1240
1251
  var expires = new Date(Date.now() + days * 864e5).toUTCString();
1252
+ camsSdk.Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
1241
1253
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1242
1254
  };
1243
1255
  var getCookie = function (name) {
@@ -1310,7 +1322,7 @@ function CAMSMSALProviderInner(_a) {
1310
1322
  React.useEffect(function () {
1311
1323
  if (typeof window !== "undefined") {
1312
1324
  if (userProfile) {
1313
- setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
1325
+ setCookie(profileStorageKey, JSON.stringify(userProfile), authOptions.activeCookiePeriod); // Store for 1 day
1314
1326
  }
1315
1327
  else {
1316
1328
  deleteCookie(profileStorageKey);
@@ -1461,7 +1473,8 @@ function CAMSProviderCore(props) {
1461
1473
  userProfile,
1462
1474
  ]);
1463
1475
  var value = React.useMemo(function () {
1464
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1476
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1477
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1465
1478
  }, [auth, userProfile, mode]);
1466
1479
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1467
1480
  }