@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.esm.js CHANGED
@@ -2391,26 +2391,22 @@ var MFAGate = function (_a) {
2391
2391
  // loginComponent: LoginComponent = DefaultLoginPage,
2392
2392
  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;
2393
2393
  var context = useCAMSContext();
2394
- var hasCalledOnAuthSuccess = useRef(false);
2394
+ var prevAccessTokenRef = useRef("");
2395
2395
  useEffect(function () {
2396
2396
  var _a;
2397
- if (context.authMode === "MSAL" && !hasCalledOnAuthSuccess.current) {
2397
+ if (context.authMode === "MSAL") {
2398
2398
  var accessToken = "accessToken" in context ? context.accessToken : "";
2399
2399
  var idToken = "idToken" in context ? context.idToken : "";
2400
- if (accessToken && idToken) {
2400
+ var requiresMFAState = "requiresMFA" in context ? context.requiresMFA : false;
2401
+ // Only call when tokens just arrived (transition from no token to token) and MFA is required
2402
+ if (accessToken && idToken && requiresMFAState && !prevAccessTokenRef.current) {
2401
2403
  var tokens = { accessToken: accessToken, idToken: idToken };
2402
2404
  onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2403
2405
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2404
- hasCalledOnAuthSuccess.current = true;
2405
2406
  }
2407
+ prevAccessTokenRef.current = accessToken;
2406
2408
  }
2407
2409
  }, [context, onAuthSuccess]);
2408
- useEffect(function () {
2409
- var accessToken = "accessToken" in context ? context.accessToken : "";
2410
- if (!accessToken) {
2411
- hasCalledOnAuthSuccess.current = false;
2412
- }
2413
- }, [context]);
2414
2410
  var validatedMFAEndpoints = useMemo(function () {
2415
2411
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
2416
2412
  if (!parsed.success) {
@@ -2431,7 +2427,9 @@ var MFAGate = function (_a) {
2431
2427
  case 0:
2432
2428
  if (context.authMode === "MSAL" && context.error) {
2433
2429
  onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(context.error);
2434
- (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2430
+ if ("onAuthError" in context) {
2431
+ (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2432
+ }
2435
2433
  }
2436
2434
  return [4 /*yield*/, context.logout()];
2437
2435
  case 1: