@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.cjs.js CHANGED
@@ -2412,26 +2412,6 @@ 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);
2416
- React.useEffect(function () {
2417
- var _a;
2418
- if (context.authMode === "MSAL" && !hasCalledOnAuthSuccess.current) {
2419
- var accessToken = "accessToken" in context ? context.accessToken : "";
2420
- var idToken = "idToken" in context ? context.idToken : "";
2421
- if (accessToken && idToken) {
2422
- var tokens = { accessToken: accessToken, idToken: idToken };
2423
- onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2424
- (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2425
- hasCalledOnAuthSuccess.current = true;
2426
- }
2427
- }
2428
- }, [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
2415
  var validatedMFAEndpoints = React.useMemo(function () {
2436
2416
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
2437
2417
  if (!parsed.success) {
@@ -2441,10 +2421,22 @@ var MFAGate = function (_a) {
2441
2421
  return parsed.data;
2442
2422
  }, [MFAEndpoints]);
2443
2423
  var handleComplete = React.useCallback(function (success) {
2444
- if (!success) {
2424
+ var _a;
2425
+ if (success && context.authMode === "MSAL") {
2426
+ var accessToken = "accessToken" in context ? context.accessToken : "";
2427
+ var idToken = "idToken" in context ? context.idToken : "";
2428
+ if (accessToken && idToken) {
2429
+ var tokens = { accessToken: accessToken, idToken: idToken };
2430
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
2431
+ if ("onAuthSuccess" in context) {
2432
+ (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
2433
+ }
2434
+ }
2435
+ }
2436
+ else if (!success) {
2445
2437
  camsSdk.Logger.error("MFA authentication failed");
2446
2438
  }
2447
- }, []);
2439
+ }, [context, onAuthSuccess]);
2448
2440
  var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2449
2441
  var _a;
2450
2442
  return __generator$1(this, function (_b) {
@@ -2452,7 +2444,9 @@ var MFAGate = function (_a) {
2452
2444
  case 0:
2453
2445
  if (context.authMode === "MSAL" && context.error) {
2454
2446
  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);
2447
+ if ("onAuthError" in context) {
2448
+ (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2449
+ }
2456
2450
  }
2457
2451
  return [4 /*yield*/, context.logout()];
2458
2452
  case 1: