@nibssplc/cams-sdk-react 0.0.1-beta.41 → 0.0.1-beta.43

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,34 @@ 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
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16818
16817
  if (typeof window !== "undefined" &&
16819
16818
  process.env.NODE_ENV !== "test") {
16820
- window.location.href = options.mfaUrl;
16819
+ // Center the popup window
16820
+ var left = (window.screen.width - 500) / 2;
16821
+ var top_1 = (window.screen.height - 600) / 2;
16822
+ var authWindow = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
16823
+ if (!authWindow) {
16824
+ camsSdk.Logger.error("Popup window blocked");
16825
+ throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
16826
+ }
16827
+ if (authWindow.closed) {
16828
+ camsSdk.Logger.error("Popup immediately closed by blocker");
16829
+ throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
16830
+ }
16831
+ (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16821
16832
  }
16822
16833
  })];
16823
16834
  case 2:
@@ -16858,7 +16869,7 @@ function useCAMSMSALAuth(options) {
16858
16869
  setAccessToken(null);
16859
16870
  setIdToken(null);
16860
16871
  setError(null);
16861
- if (typeof window !== 'undefined') {
16872
+ if (typeof window !== "undefined") {
16862
16873
  localStorage.removeItem(storageKey);
16863
16874
  }
16864
16875
  return [3 /*break*/, 3];