@nibssplc/cams-sdk-react 0.0.1-beta.40 → 0.0.1-beta.42

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.cjs.js CHANGED
@@ -16714,7 +16714,7 @@ function useCAMSMSALAuth(options) {
16714
16714
  }; }
16715
16715
  var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
16716
16716
  var account = useAccount(accounts[0] || {});
16717
- var storageKey = 'CAMS-MSAL-AUTH-SDK';
16717
+ var storageKey = "CAMS-MSAL-AUTH-SDK";
16718
16718
  var _b = React__default.useState(null), error = _b[0], setError = _b[1];
16719
16719
  var _c = React__default.useState(null), token = _c[0], setToken = _c[1];
16720
16720
  var _d = React__default.useState(null), idToken = _d[0], setIdToken = _d[1];
@@ -16724,7 +16724,7 @@ function useCAMSMSALAuth(options) {
16724
16724
  var scopes = options.scopes || ["openid", "profile", "email"];
16725
16725
  var isTokenValid = function (token) {
16726
16726
  try {
16727
- var payload = JSON.parse(atob(token.split('.')[1]));
16727
+ var payload = JSON.parse(atob(token.split(".")[1]));
16728
16728
  return payload.exp * 1000 > Date.now();
16729
16729
  }
16730
16730
  catch (_a) {
@@ -16732,7 +16732,7 @@ function useCAMSMSALAuth(options) {
16732
16732
  }
16733
16733
  };
16734
16734
  React__default.useEffect(function () {
16735
- if (typeof window !== 'undefined' && !token) {
16735
+ if (typeof window !== "undefined" && !token) {
16736
16736
  var stored = localStorage.getItem(storageKey);
16737
16737
  if (stored) {
16738
16738
  try {
@@ -16801,23 +16801,26 @@ function useCAMSMSALAuth(options) {
16801
16801
  var _a;
16802
16802
  camsSdk.Logger.debug("Login Token response:", {
16803
16803
  accessToken: accessToken,
16804
- idToken: idToken
16804
+ idToken: idToken,
16805
16805
  });
16806
16806
  setToken(response.accessToken);
16807
16807
  setAccessToken(response.accessToken);
16808
16808
  setIdToken(response.idToken);
16809
16809
  // Persist tokens to localStorage
16810
- if (typeof window !== 'undefined') {
16810
+ if (typeof window !== "undefined") {
16811
16811
  localStorage.setItem(storageKey, JSON.stringify({
16812
16812
  isAuthenticated: true,
16813
16813
  accessToken: response.accessToken,
16814
- idToken: response.idToken
16814
+ idToken: response.idToken,
16815
16815
  }));
16816
16816
  }
16817
16817
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16818
16818
  if (typeof window !== "undefined" &&
16819
16819
  process.env.NODE_ENV !== "test") {
16820
- window.location.href = options.mfaUrl;
16820
+ // Center the popup window
16821
+ var left = (window.screen.width - 500) / 2;
16822
+ var top_1 = (window.screen.height - 600) / 2;
16823
+ window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16821
16824
  }
16822
16825
  })];
16823
16826
  case 2:
@@ -16858,7 +16861,7 @@ function useCAMSMSALAuth(options) {
16858
16861
  setAccessToken(null);
16859
16862
  setIdToken(null);
16860
16863
  setError(null);
16861
- if (typeof window !== 'undefined') {
16864
+ if (typeof window !== "undefined") {
16862
16865
  localStorage.removeItem(storageKey);
16863
16866
  }
16864
16867
  return [3 /*break*/, 3];
@@ -17338,7 +17341,7 @@ function ProtectedRoute(_a) {
17338
17341
  var CAMSMSALContext = React__default.createContext(null);
17339
17342
  var setCookie = function (name, value, days) {
17340
17343
  var expires = new Date(Date.now() + days * 864e5).toUTCString();
17341
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; httpOnly; expires=").concat(expires, "; path=/; samesite=Lax");
17344
+ document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
17342
17345
  };
17343
17346
  var getCookie = function (name) {
17344
17347
  var _a;
@@ -17367,12 +17370,13 @@ function CAMSMSALProviderInner(_a) {
17367
17370
  var _this = this;
17368
17371
  var children = _a.children, authOptions = __rest(_a, ["children"]);
17369
17372
  var auth = useCAMSMSALAuth(authOptions);
17373
+ var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17370
17374
  var getInitialProfile = function () {
17371
17375
  if (typeof window === "undefined") {
17372
17376
  return null;
17373
17377
  }
17374
17378
  try {
17375
- var storedProfile = localStorage.getItem(profileStorageKey);
17379
+ var storedProfile = getCookie(profileStorageKey);
17376
17380
  return storedProfile ? JSON.parse(storedProfile) : null;
17377
17381
  }
17378
17382
  catch (_a) {
@@ -17380,7 +17384,6 @@ function CAMSMSALProviderInner(_a) {
17380
17384
  }
17381
17385
  };
17382
17386
  var _b = React__default.useState(getInitialProfile), userProfile = _b[0], setUserProfile = _b[1];
17383
- var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17384
17387
  // Load profile from storage on mount
17385
17388
  React__default.useEffect(function () {
17386
17389
  if (typeof window !== "undefined") {