@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.esm.js CHANGED
@@ -16695,7 +16695,7 @@ function useCAMSMSALAuth(options) {
16695
16695
  }; }
16696
16696
  var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
16697
16697
  var account = useAccount(accounts[0] || {});
16698
- var storageKey = 'CAMS-MSAL-AUTH-SDK';
16698
+ var storageKey = "CAMS-MSAL-AUTH-SDK";
16699
16699
  var _b = useState(null), error = _b[0], setError = _b[1];
16700
16700
  var _c = useState(null), token = _c[0], setToken = _c[1];
16701
16701
  var _d = useState(null), idToken = _d[0], setIdToken = _d[1];
@@ -16705,7 +16705,7 @@ function useCAMSMSALAuth(options) {
16705
16705
  var scopes = options.scopes || ["openid", "profile", "email"];
16706
16706
  var isTokenValid = function (token) {
16707
16707
  try {
16708
- var payload = JSON.parse(atob(token.split('.')[1]));
16708
+ var payload = JSON.parse(atob(token.split(".")[1]));
16709
16709
  return payload.exp * 1000 > Date.now();
16710
16710
  }
16711
16711
  catch (_a) {
@@ -16713,7 +16713,7 @@ function useCAMSMSALAuth(options) {
16713
16713
  }
16714
16714
  };
16715
16715
  useEffect(function () {
16716
- if (typeof window !== 'undefined' && !token) {
16716
+ if (typeof window !== "undefined" && !token) {
16717
16717
  var stored = localStorage.getItem(storageKey);
16718
16718
  if (stored) {
16719
16719
  try {
@@ -16782,23 +16782,26 @@ function useCAMSMSALAuth(options) {
16782
16782
  var _a;
16783
16783
  Logger$1.debug("Login Token response:", {
16784
16784
  accessToken: accessToken,
16785
- idToken: idToken
16785
+ idToken: idToken,
16786
16786
  });
16787
16787
  setToken(response.accessToken);
16788
16788
  setAccessToken(response.accessToken);
16789
16789
  setIdToken(response.idToken);
16790
16790
  // Persist tokens to localStorage
16791
- if (typeof window !== 'undefined') {
16791
+ if (typeof window !== "undefined") {
16792
16792
  localStorage.setItem(storageKey, JSON.stringify({
16793
16793
  isAuthenticated: true,
16794
16794
  accessToken: response.accessToken,
16795
- idToken: response.idToken
16795
+ idToken: response.idToken,
16796
16796
  }));
16797
16797
  }
16798
16798
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16799
16799
  if (typeof window !== "undefined" &&
16800
16800
  process.env.NODE_ENV !== "test") {
16801
- window.location.href = options.mfaUrl;
16801
+ // Center the popup window
16802
+ var left = (window.screen.width - 500) / 2;
16803
+ var top_1 = (window.screen.height - 600) / 2;
16804
+ window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16802
16805
  }
16803
16806
  })];
16804
16807
  case 2:
@@ -16839,7 +16842,7 @@ function useCAMSMSALAuth(options) {
16839
16842
  setAccessToken(null);
16840
16843
  setIdToken(null);
16841
16844
  setError(null);
16842
- if (typeof window !== 'undefined') {
16845
+ if (typeof window !== "undefined") {
16843
16846
  localStorage.removeItem(storageKey);
16844
16847
  }
16845
16848
  return [3 /*break*/, 3];
@@ -17319,7 +17322,7 @@ function ProtectedRoute(_a) {
17319
17322
  var CAMSMSALContext = createContext(null);
17320
17323
  var setCookie = function (name, value, days) {
17321
17324
  var expires = new Date(Date.now() + days * 864e5).toUTCString();
17322
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; httpOnly; expires=").concat(expires, "; path=/; samesite=Lax");
17325
+ document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
17323
17326
  };
17324
17327
  var getCookie = function (name) {
17325
17328
  var _a;
@@ -17348,12 +17351,13 @@ function CAMSMSALProviderInner(_a) {
17348
17351
  var _this = this;
17349
17352
  var children = _a.children, authOptions = __rest(_a, ["children"]);
17350
17353
  var auth = useCAMSMSALAuth(authOptions);
17354
+ var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17351
17355
  var getInitialProfile = function () {
17352
17356
  if (typeof window === "undefined") {
17353
17357
  return null;
17354
17358
  }
17355
17359
  try {
17356
- var storedProfile = localStorage.getItem(profileStorageKey);
17360
+ var storedProfile = getCookie(profileStorageKey);
17357
17361
  return storedProfile ? JSON.parse(storedProfile) : null;
17358
17362
  }
17359
17363
  catch (_a) {
@@ -17361,7 +17365,6 @@ function CAMSMSALProviderInner(_a) {
17361
17365
  }
17362
17366
  };
17363
17367
  var _b = useState(getInitialProfile), userProfile = _b[0], setUserProfile = _b[1];
17364
- var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17365
17368
  // Load profile from storage on mount
17366
17369
  useEffect(function () {
17367
17370
  if (typeof window !== "undefined") {