@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.cjs.js CHANGED
@@ -16719,11 +16719,12 @@ function useCAMSMSALAuth(options) {
16719
16719
  var _d = React__default.useState(null), idToken = _d[0], setIdToken = _d[1];
16720
16720
  var _e = React__default.useState(null), accessToken = _e[0], setAccessToken = _e[1];
16721
16721
  var _f = React__default.useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
16722
+ var _g = React__default.useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
16722
16723
  var isLoading = inProgress !== InteractionStatus.None;
16723
16724
  var isAuthenticated = !!account && !!token && !isMFAPending;
16724
16725
  var scopes = options.scopes || ["openid", "profile", "email"];
16725
16726
  React__default.useEffect(function () {
16726
- if (account && !isMFAPending) {
16727
+ if (account && !isMFAPending && !hasRedirected) {
16727
16728
  // Get token in foreground popup
16728
16729
  instance
16729
16730
  .acquireTokenPopup({
@@ -16737,9 +16738,13 @@ function useCAMSMSALAuth(options) {
16737
16738
  setAccessToken(response.accessToken);
16738
16739
  setIdToken(response.idToken);
16739
16740
  setIsMFAPending(true);
16740
- if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
16741
- window.location.href = options.mfaUrl;
16742
- }
16741
+ setHasRedirected(true);
16742
+ // Small delay to ensure popup closes before redirect
16743
+ setTimeout(function () {
16744
+ if (typeof window !== "undefined" && process.env.NODE_ENV !== 'test') {
16745
+ window.location.href = options.mfaUrl;
16746
+ }
16747
+ }, 100);
16743
16748
  (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16744
16749
  })
16745
16750
  .catch(function (err) {
@@ -16749,7 +16754,7 @@ function useCAMSMSALAuth(options) {
16749
16754
  (_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
16750
16755
  });
16751
16756
  }
16752
- }, [account, instance, isMFAPending]);
16757
+ }, [account, instance, isMFAPending, hasRedirected]);
16753
16758
  var login = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
16754
16759
  var err_1, redirectErr_1, camsError_1, camsError;
16755
16760
  var _a, _b, _c;
@@ -16760,7 +16765,7 @@ function useCAMSMSALAuth(options) {
16760
16765
  _d.label = 1;
16761
16766
  case 1:
16762
16767
  _d.trys.push([1, 3, , 8]);
16763
- return [4 /*yield*/, instance.loginPopup({
16768
+ return [4 /*yield*/, instance.loginRedirect({
16764
16769
  scopes: scopes,
16765
16770
  prompt: options.prompt || "login",
16766
16771
  })];
@@ -16808,6 +16813,7 @@ function useCAMSMSALAuth(options) {
16808
16813
  setToken(null);
16809
16814
  setError(null);
16810
16815
  setIsMFAPending(false);
16816
+ setHasRedirected(false);
16811
16817
  return [3 /*break*/, 3];
16812
16818
  case 2:
16813
16819
  err_2 = _a.sent();