@nibssplc/cams-sdk-react 1.0.0-rc.97 → 1.0.0-rc.99

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
@@ -1411,15 +1411,15 @@ var useOTPHandler = function (_a) {
1411
1411
  return __generator$1(this, function (_a) {
1412
1412
  switch (_a.label) {
1413
1413
  case 0:
1414
- if (isMaxAttemptsReached) {
1415
- onAuthComplete(false, {
1414
+ if (!isMaxAttemptsReached) return [3 /*break*/, 2];
1415
+ return [4 /*yield*/, onAuthComplete(false, {
1416
1416
  message: "Maximum attempts reached",
1417
- });
1418
- return [2 /*return*/, false];
1419
- }
1420
- _a.label = 1;
1417
+ })];
1421
1418
  case 1:
1422
- _a.trys.push([1, 3, 4, 5]);
1419
+ _a.sent();
1420
+ return [2 /*return*/, false];
1421
+ case 2:
1422
+ _a.trys.push([2, 11, 13, 14]);
1423
1423
  setLoading(true);
1424
1424
  currentAttempt = attemptCount + 1;
1425
1425
  setAttemptCount(currentAttempt);
@@ -1430,41 +1430,43 @@ var useOTPHandler = function (_a) {
1430
1430
  email: email,
1431
1431
  MFACode: authenticationValue,
1432
1432
  }, MFAEndpoint || "")];
1433
- case 2:
1434
- response = _a.sent();
1435
- if (response) {
1436
- onAuthComplete(true, response);
1437
- return [2 /*return*/, true];
1438
- }
1439
- else {
1440
- if (currentAttempt >= MAX_ATTEMPTS) {
1441
- setIsMaxAttemptsReached(true);
1442
- onAuthComplete(false, {
1443
- message: "Maximum Attempts Reached",
1444
- });
1445
- }
1446
- else {
1447
- onAuthComplete(false, response);
1448
- }
1449
- return [2 /*return*/, false];
1450
- }
1451
1433
  case 3:
1434
+ response = _a.sent();
1435
+ if (!response) return [3 /*break*/, 5];
1436
+ return [4 /*yield*/, onAuthComplete(true, response)];
1437
+ case 4:
1438
+ _a.sent();
1439
+ return [2 /*return*/, true];
1440
+ case 5:
1441
+ if (!(currentAttempt >= MAX_ATTEMPTS)) return [3 /*break*/, 7];
1442
+ setIsMaxAttemptsReached(true);
1443
+ return [4 /*yield*/, onAuthComplete(false, {
1444
+ message: "Maximum Attempts Reached",
1445
+ })];
1446
+ case 6:
1447
+ _a.sent();
1448
+ return [3 /*break*/, 9];
1449
+ case 7: return [4 /*yield*/, onAuthComplete(false, response)];
1450
+ case 8:
1451
+ _a.sent();
1452
+ _a.label = 9;
1453
+ case 9: return [2 /*return*/, false];
1454
+ case 10: return [3 /*break*/, 14];
1455
+ case 11:
1452
1456
  error_1 = _a.sent();
1453
1457
  console.error(error_1);
1454
1458
  currentAttempt = attemptCount + 1;
1455
1459
  if (currentAttempt >= MAX_ATTEMPTS) {
1456
1460
  setIsMaxAttemptsReached(true);
1457
- onAuthComplete(false, error_1);
1458
- }
1459
- else {
1460
- onAuthComplete(false, error_1);
1461
1461
  }
1462
- onAuthComplete(false, error_1);
1462
+ return [4 /*yield*/, onAuthComplete(false, error_1)];
1463
+ case 12:
1464
+ _a.sent();
1463
1465
  return [2 /*return*/, false];
1464
- case 4:
1466
+ case 13:
1465
1467
  setLoading(false);
1466
1468
  return [7 /*endfinally*/];
1467
- case 5: return [2 /*return*/];
1469
+ case 14: return [2 /*return*/];
1468
1470
  }
1469
1471
  });
1470
1472
  }); }; }, [onAuthComplete, MFAEndpoint, attemptCount, isMaxAttemptsReached]);
@@ -1561,31 +1563,40 @@ var MFAOptions = function (_a) {
1561
1563
  email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || context.email,
1562
1564
  appCode: context.appCode || "",
1563
1565
  MFAEndpoint: MFAEndpoints.ValidateUserMFA,
1564
- onAuthComplete: function (state, data) {
1565
- console.log("Completed Auth. Handling MFA", state, data);
1566
- if (state && (data === null || data === void 0 ? void 0 : data.isValid)) {
1567
- // Call completeMFA to update context state
1568
- console.log("IN Complete MFA Block. Handling MFA", data);
1569
- completeMFA === null || completeMFA === void 0 ? void 0 : completeMFA(data).catch(function (error) {
1570
- console.error("Failed to complete MFA:", error);
1571
- });
1572
- setShowSuccessAnimation(true);
1573
- toast.success(jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsx(ShieldCheck, { className: "w-4 h-4" }), jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
1574
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1575
- }
1576
- else {
1577
- toast.error(jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsx(ShieldClose, { className: "w-4 h-4" }), jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
1578
- if (isMaxAttemptsReached) {
1579
- setTimeout(function () {
1580
- logout().then(function () {
1581
- onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1582
- onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1583
- });
1584
- }, 3000);
1566
+ onAuthComplete: function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1567
+ return __generator$1(this, function (_a) {
1568
+ switch (_a.label) {
1569
+ case 0:
1570
+ console.log("Completed Auth. Handling MFA", state, data);
1571
+ if (!(state && (data === null || data === void 0 ? void 0 : data.isValid))) return [3 /*break*/, 2];
1572
+ // Call completeMFA to update context state
1573
+ console.log("IN Complete MFA Block. Handling MFA", data);
1574
+ return [4 /*yield*/, (completeMFA === null || completeMFA === void 0 ? void 0 : completeMFA(data).catch(function (error) {
1575
+ console.error("Failed to complete MFA:", error);
1576
+ }))];
1577
+ case 1:
1578
+ _a.sent();
1579
+ toast.success(jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsx(ShieldCheck, { className: "w-4 h-4" }), jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
1580
+ setShowSuccessAnimation(true);
1581
+ return [3 /*break*/, 3];
1582
+ case 2:
1583
+ toast.error(jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsx(ShieldClose, { className: "w-4 h-4" }), jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
1584
+ if (isMaxAttemptsReached) {
1585
+ setTimeout(function () {
1586
+ logout().then(function () {
1587
+ onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1588
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1589
+ });
1590
+ }, 3000);
1591
+ }
1592
+ _a.label = 3;
1593
+ case 3: return [2 /*return*/];
1585
1594
  }
1586
- }
1587
- },
1588
- }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1595
+ });
1596
+ }); },
1597
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading,
1598
+ // setLoading,
1599
+ attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1589
1600
  var handleGoBack = function () {
1590
1601
  setAuthType(null);
1591
1602
  setOtpVisible(false);
@@ -1594,9 +1605,7 @@ var MFAOptions = function (_a) {
1594
1605
  };
1595
1606
  // Show success animation if authentication is successful
1596
1607
  if (showSuccessAnimation) {
1597
- return (jsx("div", { className: "flex justify-center items-center h-dvh", children: jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsx(AuthSuccessAnimation, { onComplete: function () {
1598
- // Animation completed, can add additional logic here if needed
1599
- } }) }) }));
1608
+ return (jsx("div", { className: "flex justify-center items-center h-dvh", children: jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsx(AuthSuccessAnimation, { onComplete: function () { return onComplete(true); } }) }) }));
1600
1609
  }
1601
1610
  var content = jsx(Fragment, {});
1602
1611
  if (!authType) {
@@ -1832,14 +1841,16 @@ var MFAGate = function (_a) {
1832
1841
  var contextAccessToken = "accessToken" in context ? context.accessToken : "";
1833
1842
  var handleComplete = useCallback(function (success) {
1834
1843
  var _a;
1835
- if (success && context.authMode === "MSAL") {
1844
+ if (success) {
1836
1845
  var accessToken = "accessToken" in context ? context.accessToken : "";
1837
1846
  var idToken = "idToken" in context ? context.idToken : "";
1838
- if (accessToken && idToken) {
1847
+ Logger.info("MFA Authentication Successful", { context: context || null });
1848
+ context.isAuthenticated = true;
1849
+ setAuthState("Authenticated");
1850
+ if (context.authMode === "MSAL") {
1839
1851
  var tokens = { accessToken: accessToken, idToken: idToken };
1840
1852
  onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
1841
1853
  if ("onAuthSuccess" in context) {
1842
- context.isAuthenticated = true;
1843
1854
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1844
1855
  }
1845
1856
  }