@nibssplc/cams-sdk-react 0.0.1-beta.69 → 0.0.1-beta.70
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/components/MFAOptions.d.ts +2 -1
- package/dist/index.cjs.js +37 -35
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +37 -35
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
interface MFAOptionsProps {
|
|
2
2
|
onComplete?: (success: boolean) => void;
|
|
3
|
+
onAuthFailed?: () => void;
|
|
3
4
|
MFAEndpoint?: string;
|
|
4
5
|
}
|
|
5
|
-
declare const MFAOptions: ({ onComplete, MFAEndpoint }?: MFAOptionsProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare const MFAOptions: ({ onComplete, onAuthFailed, MFAEndpoint }?: MFAOptionsProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
export default MFAOptions;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1738,7 +1738,7 @@ var useOTPHandler = function (_a) {
|
|
|
1738
1738
|
};
|
|
1739
1739
|
|
|
1740
1740
|
var MFAOptions = function (_a) {
|
|
1741
|
-
var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, MFAEndpoint = _b.MFAEndpoint;
|
|
1741
|
+
var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, onAuthFailed = _b.onAuthFailed, MFAEndpoint = _b.MFAEndpoint;
|
|
1742
1742
|
var _c = React.useState(""), value = _c[0], setValue = _c[1];
|
|
1743
1743
|
var _d = React.useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
|
|
1744
1744
|
var _e = React.useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
|
|
@@ -1747,7 +1747,9 @@ var MFAOptions = function (_a) {
|
|
|
1747
1747
|
var context = useCAMSContext();
|
|
1748
1748
|
var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1749
1749
|
? context
|
|
1750
|
-
: { sendEmailOTP: null, completeMFA: null
|
|
1750
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1751
|
+
return [2 /*return*/];
|
|
1752
|
+
}); }); } }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA, logout = _h.logout;
|
|
1751
1753
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1752
1754
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1753
1755
|
var _j = useOTPHandler({
|
|
@@ -1757,39 +1759,30 @@ var MFAOptions = function (_a) {
|
|
|
1757
1759
|
appCode: context.appCode || "",
|
|
1758
1760
|
authenticationType: authType,
|
|
1759
1761
|
MFAEndpoint: MFAEndpoint,
|
|
1760
|
-
onAuthComplete: function (state, data) {
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
|
|
1782
|
-
return [3 /*break*/, 6];
|
|
1783
|
-
case 5:
|
|
1784
|
-
sonner.toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(lucideReact.ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
|
|
1785
|
-
if (isMaxAttemptsReached) {
|
|
1786
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
|
|
1787
|
-
}
|
|
1788
|
-
_a.label = 6;
|
|
1789
|
-
case 6: return [2 /*return*/];
|
|
1762
|
+
onAuthComplete: function (state, data) {
|
|
1763
|
+
if (state) {
|
|
1764
|
+
// Call completeMFA to update context state
|
|
1765
|
+
if (completeMFA && authType && lastOTPCode) {
|
|
1766
|
+
completeMFA(lastOTPCode, authType).catch(function (error) {
|
|
1767
|
+
console.error("Failed to complete MFA:", error);
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
setShowSuccessAnimation(true);
|
|
1771
|
+
sonner.toast.success(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
|
|
1772
|
+
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
|
|
1773
|
+
}
|
|
1774
|
+
else {
|
|
1775
|
+
sonner.toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(lucideReact.ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
|
|
1776
|
+
if (isMaxAttemptsReached) {
|
|
1777
|
+
setTimeout(function () {
|
|
1778
|
+
logout().then(function () {
|
|
1779
|
+
onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
|
|
1780
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
|
|
1781
|
+
});
|
|
1782
|
+
}, 1000);
|
|
1790
1783
|
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1784
|
+
}
|
|
1785
|
+
},
|
|
1793
1786
|
}), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
|
|
1794
1787
|
var handleGoBack = function () {
|
|
1795
1788
|
setAuthType(null);
|
|
@@ -1888,7 +1881,16 @@ var MFAGate = function (_a) {
|
|
|
1888
1881
|
if (!success) {
|
|
1889
1882
|
console.error("MFA authentication failed");
|
|
1890
1883
|
}
|
|
1891
|
-
}
|
|
1884
|
+
}, onAuthFailed: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1885
|
+
return __generator(this, function (_a) {
|
|
1886
|
+
switch (_a.label) {
|
|
1887
|
+
case 0: return [4 /*yield*/, context.logout()];
|
|
1888
|
+
case 1:
|
|
1889
|
+
_a.sent();
|
|
1890
|
+
return [2 /*return*/];
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
}); } }));
|
|
1892
1894
|
}
|
|
1893
1895
|
if (!isAuthenticated) {
|
|
1894
1896
|
return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));
|