@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
package/dist/index.esm.js
CHANGED
|
@@ -1718,7 +1718,7 @@ var useOTPHandler = function (_a) {
|
|
|
1718
1718
|
};
|
|
1719
1719
|
|
|
1720
1720
|
var MFAOptions = function (_a) {
|
|
1721
|
-
var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, MFAEndpoint = _b.MFAEndpoint;
|
|
1721
|
+
var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, onAuthFailed = _b.onAuthFailed, MFAEndpoint = _b.MFAEndpoint;
|
|
1722
1722
|
var _c = useState(""), value = _c[0], setValue = _c[1];
|
|
1723
1723
|
var _d = useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
|
|
1724
1724
|
var _e = useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
|
|
@@ -1727,7 +1727,9 @@ var MFAOptions = function (_a) {
|
|
|
1727
1727
|
var context = useCAMSContext();
|
|
1728
1728
|
var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1729
1729
|
? context
|
|
1730
|
-
: { sendEmailOTP: null, completeMFA: null
|
|
1730
|
+
: { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1731
|
+
return [2 /*return*/];
|
|
1732
|
+
}); }); } }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA, logout = _h.logout;
|
|
1731
1733
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1732
1734
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1733
1735
|
var _j = useOTPHandler({
|
|
@@ -1737,39 +1739,30 @@ var MFAOptions = function (_a) {
|
|
|
1737
1739
|
appCode: context.appCode || "",
|
|
1738
1740
|
authenticationType: authType,
|
|
1739
1741
|
MFAEndpoint: MFAEndpoint,
|
|
1740
|
-
onAuthComplete: function (state, data) {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
_a.label = 1;
|
|
1748
|
-
case 1:
|
|
1749
|
-
_a.trys.push([1, 3, , 4]);
|
|
1750
|
-
return [4 /*yield*/, completeMFA(lastOTPCode, authType)];
|
|
1751
|
-
case 2:
|
|
1752
|
-
_a.sent();
|
|
1753
|
-
return [3 /*break*/, 4];
|
|
1754
|
-
case 3:
|
|
1755
|
-
error_1 = _a.sent();
|
|
1756
|
-
console.error("Failed to complete MFA:", error_1);
|
|
1757
|
-
return [3 /*break*/, 4];
|
|
1758
|
-
case 4:
|
|
1759
|
-
setShowSuccessAnimation(true);
|
|
1760
|
-
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(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
|
|
1761
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
|
|
1762
|
-
return [3 /*break*/, 6];
|
|
1763
|
-
case 5:
|
|
1764
|
-
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(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
|
|
1765
|
-
if (isMaxAttemptsReached) {
|
|
1766
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
|
|
1767
|
-
}
|
|
1768
|
-
_a.label = 6;
|
|
1769
|
-
case 6: return [2 /*return*/];
|
|
1742
|
+
onAuthComplete: function (state, data) {
|
|
1743
|
+
if (state) {
|
|
1744
|
+
// Call completeMFA to update context state
|
|
1745
|
+
if (completeMFA && authType && lastOTPCode) {
|
|
1746
|
+
completeMFA(lastOTPCode, authType).catch(function (error) {
|
|
1747
|
+
console.error("Failed to complete MFA:", error);
|
|
1748
|
+
});
|
|
1770
1749
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1750
|
+
setShowSuccessAnimation(true);
|
|
1751
|
+
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(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
|
|
1752
|
+
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
|
|
1753
|
+
}
|
|
1754
|
+
else {
|
|
1755
|
+
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(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
|
|
1756
|
+
if (isMaxAttemptsReached) {
|
|
1757
|
+
setTimeout(function () {
|
|
1758
|
+
logout().then(function () {
|
|
1759
|
+
onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
|
|
1760
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
|
|
1761
|
+
});
|
|
1762
|
+
}, 1000);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
},
|
|
1773
1766
|
}), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
|
|
1774
1767
|
var handleGoBack = function () {
|
|
1775
1768
|
setAuthType(null);
|
|
@@ -1868,7 +1861,16 @@ var MFAGate = function (_a) {
|
|
|
1868
1861
|
if (!success) {
|
|
1869
1862
|
console.error("MFA authentication failed");
|
|
1870
1863
|
}
|
|
1871
|
-
}
|
|
1864
|
+
}, onAuthFailed: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1865
|
+
return __generator(this, function (_a) {
|
|
1866
|
+
switch (_a.label) {
|
|
1867
|
+
case 0: return [4 /*yield*/, context.logout()];
|
|
1868
|
+
case 1:
|
|
1869
|
+
_a.sent();
|
|
1870
|
+
return [2 /*return*/];
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1873
|
+
}); } }));
|
|
1872
1874
|
}
|
|
1873
1875
|
if (!isAuthenticated) {
|
|
1874
1876
|
return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));
|