@nibssplc/cams-sdk-react 1.0.0-rc.52 → 1.0.0-rc.53

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
@@ -2412,26 +2412,22 @@ var MFAGate = function (_a) {
2412
2412
  // loginComponent: LoginComponent = DefaultLoginPage,
2413
2413
  usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA, onAuthSuccess = _a.onAuthSuccess, onAuthError = _a.onAuthError;
2414
2414
  var context = useCAMSContext();
2415
- var hasCalledOnAuthSuccess = React.useRef(false);
2415
+ var prevAccessTokenRef = React.useRef("");
2416
2416
  React.useEffect(function () {
2417
2417
  var _a;
2418
- if (context.authMode === "MSAL" && !hasCalledOnAuthSuccess.current) {
2418
+ if (context.authMode === "MSAL") {
2419
2419
  var accessToken = "accessToken" in context ? context.accessToken : "";
2420
2420
  var idToken = "idToken" in context ? context.idToken : "";
2421
- if (accessToken && idToken) {
2421
+ var requiresMFAState = "requiresMFA" in context ? context.requiresMFA : false;
2422
+ // Only call when tokens just arrived (transition from no token to token) and MFA is required
2423
+ if (accessToken && idToken && requiresMFAState && !prevAccessTokenRef.current) {
2422
2424
  var tokens = { accessToken: accessToken, idToken: idToken };
2423
2425
  onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2424
2426
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2425
- hasCalledOnAuthSuccess.current = true;
2426
2427
  }
2428
+ prevAccessTokenRef.current = accessToken;
2427
2429
  }
2428
2430
  }, [context, onAuthSuccess]);
2429
- React.useEffect(function () {
2430
- var accessToken = "accessToken" in context ? context.accessToken : "";
2431
- if (!accessToken) {
2432
- hasCalledOnAuthSuccess.current = false;
2433
- }
2434
- }, [context]);
2435
2431
  var validatedMFAEndpoints = React.useMemo(function () {
2436
2432
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
2437
2433
  if (!parsed.success) {
@@ -2452,7 +2448,9 @@ var MFAGate = function (_a) {
2452
2448
  case 0:
2453
2449
  if (context.authMode === "MSAL" && context.error) {
2454
2450
  onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(context.error);
2455
- (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2451
+ if ("onAuthError" in context) {
2452
+ (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2453
+ }
2456
2454
  }
2457
2455
  return [4 /*yield*/, context.logout()];
2458
2456
  case 1: