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

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