@nibssplc/cams-sdk-react 1.0.0-rc.50 → 1.0.0-rc.51

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,6 +2391,24 @@ 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);
2395
+ useEffect(function () {
2396
+ var _a;
2397
+ if (context.authMode === "MSAL" && context.accessToken && context.idToken && !hasCalledOnAuthSuccess.current) {
2398
+ var tokens = {
2399
+ accessToken: context.accessToken,
2400
+ idToken: context.idToken,
2401
+ };
2402
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2403
+ (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2404
+ hasCalledOnAuthSuccess.current = true;
2405
+ }
2406
+ }, [context.accessToken, context.idToken, context.authMode, onAuthSuccess, context]);
2407
+ useEffect(function () {
2408
+ if (!context.accessToken) {
2409
+ hasCalledOnAuthSuccess.current = false;
2410
+ }
2411
+ }, [context.accessToken]);
2394
2412
  var validatedMFAEndpoints = useMemo(function () {
2395
2413
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
2396
2414
  if (!parsed.success) {
@@ -2400,19 +2418,10 @@ var MFAGate = function (_a) {
2400
2418
  return parsed.data;
2401
2419
  }, [MFAEndpoints]);
2402
2420
  var handleComplete = useCallback(function (success) {
2403
- var _a;
2404
- if (success && context.authMode === "MSAL") {
2405
- var tokens = {
2406
- accessToken: context.accessToken,
2407
- idToken: context.idToken,
2408
- };
2409
- onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2410
- (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2411
- }
2412
- else if (!success) {
2421
+ if (!success) {
2413
2422
  Logger.error("MFA authentication failed");
2414
2423
  }
2415
- }, [context, onAuthSuccess]);
2424
+ }, []);
2416
2425
  var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2417
2426
  var _a;
2418
2427
  return __generator$1(this, function (_b) {