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

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
@@ -16699,45 +16699,39 @@ function useCAMSMSALAuth(options) {
16699
16699
  var _c = useState(null), token = _c[0], setToken = _c[1];
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
- var _f = useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
16703
- var _g = useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
16704
16702
  var isLoading = inProgress !== InteractionStatus.None;
16705
- var isAuthenticated = !!account && !!token && !isMFAPending;
16703
+ var isAuthenticated = !!account && !!token;
16706
16704
  var scopes = options.scopes || ["openid", "profile", "email"];
16707
- useEffect(function () {
16708
- if (account && !isMFAPending && !hasRedirected) {
16709
- // Get token in foreground popup
16710
- instance
16711
- .acquireTokenPopup({
16712
- scopes: scopes,
16713
- account: account,
16714
- prompt: options.prompt || "login",
16715
- })
16716
- .then(function (response) {
16717
- var _a;
16718
- setToken(response.accessToken);
16719
- setAccessToken(response.accessToken);
16720
- setIdToken(response.idToken);
16721
- setIsMFAPending(true);
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);
16729
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16730
- })
16731
- .catch(function (err) {
16732
- var _a;
16733
- var camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
16734
- setError(camsError);
16735
- (_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
16736
- });
16737
- }
16738
- }, [account, instance, isMFAPending, hasRedirected]);
16705
+ // useEffect(() => {
16706
+ // const handleRedirect = async () => {
16707
+ // try {
16708
+ // const response = await instance.handleRedirectPromise();
16709
+ // if (response) {
16710
+ // const account = response.account;
16711
+ // instance.setActiveAccount(account);
16712
+ // const tokenResponse = await instance.acquireTokenSilent({
16713
+ // scopes,
16714
+ // account,
16715
+ // });
16716
+ // setToken(tokenResponse.accessToken);
16717
+ // setAccessToken(tokenResponse.accessToken);
16718
+ // setIdToken(tokenResponse.idToken);
16719
+ // options.onAuthSuccess?.(tokenResponse.accessToken);
16720
+ // if (
16721
+ // typeof window !== "undefined" &&
16722
+ // process.env.NODE_ENV !== "test"
16723
+ // ) {
16724
+ // window.location.href = options.mfaUrl!;
16725
+ // }
16726
+ // }
16727
+ // } catch (err) {
16728
+ // console.error("Redirect handling failed:", err);
16729
+ // }
16730
+ // };
16731
+ // handleRedirect();
16732
+ // }, []);
16739
16733
  var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
16740
- var err_1, redirectErr_1, camsError_1, camsError;
16734
+ var err_1, camsError_1, camsError;
16741
16735
  var _a, _b, _c;
16742
16736
  return __generator(this, function (_d) {
16743
16737
  switch (_d.label) {
@@ -16745,40 +16739,49 @@ function useCAMSMSALAuth(options) {
16745
16739
  setError(null);
16746
16740
  _d.label = 1;
16747
16741
  case 1:
16748
- _d.trys.push([1, 3, , 8]);
16749
- return [4 /*yield*/, instance.loginRedirect({
16742
+ _d.trys.push([1, 3, , 4]);
16743
+ // await instance.loginRedirect({
16744
+ // scopes,
16745
+ // prompt: options.prompt || "login",
16746
+ // });
16747
+ return [4 /*yield*/, instance
16748
+ .loginPopup({
16750
16749
  scopes: scopes,
16751
16750
  prompt: options.prompt || "login",
16751
+ })
16752
+ .then(function (response) {
16753
+ var _a;
16754
+ setToken(response.accessToken);
16755
+ setAccessToken(response.accessToken);
16756
+ setIdToken(response.idToken);
16757
+ (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
16758
+ if (typeof window !== "undefined" &&
16759
+ process.env.NODE_ENV !== "test") {
16760
+ window.location.href = options.mfaUrl;
16761
+ }
16752
16762
  })];
16753
16763
  case 2:
16764
+ // await instance.loginRedirect({
16765
+ // scopes,
16766
+ // prompt: options.prompt || "login",
16767
+ // });
16754
16768
  _d.sent();
16755
- return [3 /*break*/, 8];
16769
+ return [3 /*break*/, 4];
16756
16770
  case 3:
16757
16771
  err_1 = _d.sent();
16758
- if (!(err_1.errorCode === "popup_window_error" ||
16759
- ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup")))) return [3 /*break*/, 7];
16760
- _d.label = 4;
16761
- case 4:
16762
- _d.trys.push([4, 6, , 7]);
16763
- return [4 /*yield*/, instance.loginRedirect({
16764
- scopes: scopes,
16765
- prompt: options.prompt || "login",
16766
- })];
16767
- case 5:
16768
- _d.sent();
16769
- return [2 /*return*/];
16770
- case 6:
16771
- redirectErr_1 = _d.sent();
16772
- camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
16773
- setError(camsError_1);
16774
- (_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
16775
- return [2 /*return*/];
16776
- case 7:
16772
+ // If popup is blocked
16773
+ if (err_1.errorCode === "popup_window_error" ||
16774
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
16775
+ camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + err_1);
16776
+ setError(camsError_1);
16777
+ (_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
16778
+ return [2 /*return*/];
16779
+ }
16777
16780
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
16778
16781
  setError(camsError);
16779
16782
  (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
16780
- return [3 /*break*/, 8];
16781
- case 8: return [2 /*return*/];
16783
+ return [3 /*break*/, 4];
16784
+ case 4: return [2 /*return*/];
16782
16785
  }
16783
16786
  });
16784
16787
  }); }, [instance, scopes, options]);
@@ -16793,8 +16796,6 @@ function useCAMSMSALAuth(options) {
16793
16796
  _a.sent();
16794
16797
  setToken(null);
16795
16798
  setError(null);
16796
- setIsMFAPending(false);
16797
- setHasRedirected(false);
16798
16799
  return [3 /*break*/, 3];
16799
16800
  case 2:
16800
16801
  err_2 = _a.sent();
@@ -16810,7 +16811,6 @@ function useCAMSMSALAuth(options) {
16810
16811
  logout: logout,
16811
16812
  isAuthenticated: isAuthenticated,
16812
16813
  isLoading: isLoading,
16813
- isMFAPending: isMFAPending,
16814
16814
  error: error,
16815
16815
  token: token,
16816
16816
  idToken: idToken,