@nibssplc/cams-sdk-react 0.0.1-beta.31 → 0.0.1-beta.32

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
@@ -16700,11 +16700,12 @@ function useCAMSMSALAuth(options) {
16700
16700
  var _d = useState(null), idToken = _d[0], setIdToken = _d[1];
16701
16701
  var _e = useState(null), accessToken = _e[0], setAccessToken = _e[1];
16702
16702
  var _f = useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
16703
+ var _g = useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
16703
16704
  var isLoading = inProgress !== InteractionStatus.None;
16704
16705
  var isAuthenticated = !!account && !!token && !isMFAPending;
16705
16706
  var scopes = options.scopes || ["openid", "profile", "email"];
16706
16707
  useEffect(function () {
16707
- if (account && !isMFAPending) {
16708
+ if (account && !isMFAPending && !hasRedirected) {
16708
16709
  // Get token in foreground popup
16709
16710
  instance
16710
16711
  .acquireTokenPopup({
@@ -16718,9 +16719,13 @@ function useCAMSMSALAuth(options) {
16718
16719
  setAccessToken(response.accessToken);
16719
16720
  setIdToken(response.idToken);
16720
16721
  setIsMFAPending(true);
16721
- if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
16722
- window.location.href = options.mfaUrl;
16723
- }
16722
+ setHasRedirected(true);
16723
+ // Small delay to ensure popup closes before redirect
16724
+ setTimeout(function () {
16725
+ if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
16726
+ window.location.href = options.mfaUrl;
16727
+ }
16728
+ }, 100);
16724
16729
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16725
16730
  })
16726
16731
  .catch(function (err) {
@@ -16730,7 +16735,7 @@ function useCAMSMSALAuth(options) {
16730
16735
  (_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
16731
16736
  });
16732
16737
  }
16733
- }, [account, instance, isMFAPending]);
16738
+ }, [account, instance, isMFAPending, hasRedirected]);
16734
16739
  var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
16735
16740
  var err_1, redirectErr_1, camsError_1, camsError;
16736
16741
  var _a, _b, _c;
@@ -16741,7 +16746,7 @@ function useCAMSMSALAuth(options) {
16741
16746
  _d.label = 1;
16742
16747
  case 1:
16743
16748
  _d.trys.push([1, 3, , 8]);
16744
- return [4 /*yield*/, instance.loginPopup({
16749
+ return [4 /*yield*/, instance.loginRedirect({
16745
16750
  scopes: scopes,
16746
16751
  prompt: options.prompt || "login",
16747
16752
  })];
@@ -16789,6 +16794,7 @@ function useCAMSMSALAuth(options) {
16789
16794
  setToken(null);
16790
16795
  setError(null);
16791
16796
  setIsMFAPending(false);
16797
+ setHasRedirected(false);
16792
16798
  return [3 /*break*/, 3];
16793
16799
  case 2:
16794
16800
  err_2 = _a.sent();