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

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.
@@ -1,6 +1,6 @@
1
1
  import { MFAEndpoints } from "./MFAGate";
2
2
  interface MFAOptionsProps {
3
- onComplete?: (success: boolean) => void;
3
+ onComplete: (success: boolean) => void;
4
4
  onAuthFailed?: () => void;
5
5
  MFAEndpoints: MFAEndpoints;
6
6
  usePassKey?: boolean;
package/dist/index.cjs.js CHANGED
@@ -1582,31 +1582,41 @@ var MFAOptions = function (_a) {
1582
1582
  email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || context.email,
1583
1583
  appCode: context.appCode || "",
1584
1584
  MFAEndpoint: MFAEndpoints.ValidateUserMFA,
1585
- onAuthComplete: function (state, data) {
1586
- console.log("Completed Auth. Handling MFA", state, data);
1587
- if (state && (data === null || data === void 0 ? void 0 : data.isValid)) {
1588
- // Call completeMFA to update context state
1589
- console.log("IN Complete MFA Block. Handling MFA", data);
1590
- completeMFA === null || completeMFA === void 0 ? void 0 : completeMFA(data).catch(function (error) {
1591
- console.error("Failed to complete MFA:", error);
1592
- });
1593
- setShowSuccessAnimation(true);
1594
- sonner.toast.success(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4" }), jsxRuntime.jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
1595
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1596
- }
1597
- else {
1598
- sonner.toast.error(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldClose, { className: "w-4 h-4" }), jsxRuntime.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
1599
- if (isMaxAttemptsReached) {
1600
- setTimeout(function () {
1601
- logout().then(function () {
1602
- onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1603
- onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1604
- });
1605
- }, 3000);
1585
+ onAuthComplete: function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1586
+ return __generator$1(this, function (_a) {
1587
+ switch (_a.label) {
1588
+ case 0:
1589
+ console.log("Completed Auth. Handling MFA", state, data);
1590
+ if (!(state && (data === null || data === void 0 ? void 0 : data.isValid))) return [3 /*break*/, 2];
1591
+ // Call completeMFA to update context state
1592
+ console.log("IN Complete MFA Block. Handling MFA", data);
1593
+ return [4 /*yield*/, (completeMFA === null || completeMFA === void 0 ? void 0 : completeMFA(data).catch(function (error) {
1594
+ console.error("Failed to complete MFA:", error);
1595
+ }))];
1596
+ case 1:
1597
+ _a.sent();
1598
+ onComplete(true);
1599
+ sonner.toast.success(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4" }), jsxRuntime.jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
1600
+ setTimeout(function () { return setShowSuccessAnimation(true); }, 2000);
1601
+ return [3 /*break*/, 3];
1602
+ case 2:
1603
+ sonner.toast.error(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldClose, { className: "w-4 h-4" }), jsxRuntime.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
1604
+ if (isMaxAttemptsReached) {
1605
+ setTimeout(function () {
1606
+ logout().then(function () {
1607
+ onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1608
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1609
+ });
1610
+ }, 3000);
1611
+ }
1612
+ _a.label = 3;
1613
+ case 3: return [2 /*return*/];
1606
1614
  }
1607
- }
1608
- },
1609
- }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1615
+ });
1616
+ }); },
1617
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading,
1618
+ // setLoading,
1619
+ attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1610
1620
  var handleGoBack = function () {
1611
1621
  setAuthType(null);
1612
1622
  setOtpVisible(false);
@@ -1853,14 +1863,15 @@ var MFAGate = function (_a) {
1853
1863
  var contextAccessToken = "accessToken" in context ? context.accessToken : "";
1854
1864
  var handleComplete = React.useCallback(function (success) {
1855
1865
  var _a;
1856
- if (success && context.authMode === "MSAL") {
1866
+ if (success) {
1857
1867
  var accessToken = "accessToken" in context ? context.accessToken : "";
1858
1868
  var idToken = "idToken" in context ? context.idToken : "";
1859
- if (accessToken && idToken) {
1869
+ camsSdk.Logger.info("MFA Authentication Successful", { context: context || null });
1870
+ context.isAuthenticated = true;
1871
+ if (context.authMode === "MSAL") {
1860
1872
  var tokens = { accessToken: accessToken, idToken: idToken };
1861
1873
  onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
1862
1874
  if ("onAuthSuccess" in context) {
1863
- context.isAuthenticated = true;
1864
1875
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1865
1876
  }
1866
1877
  }