@nibssplc/cams-sdk-react 0.0.1-beta.68 → 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 +41 -39
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +41 -39
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -281,7 +281,6 @@ function useCAMSMSALAuth(options) {
|
|
|
281
281
|
setRequiresMFA(true);
|
|
282
282
|
}
|
|
283
283
|
console.log("App Code >>>", options.appCode);
|
|
284
|
-
console.log("MFA Endpoint >>>", options.MFAEndpoint);
|
|
285
284
|
}
|
|
286
285
|
else {
|
|
287
286
|
localStorage.removeItem(storageKey);
|
|
@@ -1719,7 +1718,7 @@ var useOTPHandler = function (_a) {
|
|
|
1719
1718
|
};
|
|
1720
1719
|
|
|
1721
1720
|
var MFAOptions = function (_a) {
|
|
1722
|
-
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;
|
|
1723
1722
|
var _c = useState(""), value = _c[0], setValue = _c[1];
|
|
1724
1723
|
var _d = useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
|
|
1725
1724
|
var _e = useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
|
|
@@ -1728,7 +1727,9 @@ var MFAOptions = function (_a) {
|
|
|
1728
1727
|
var context = useCAMSContext();
|
|
1729
1728
|
var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
|
|
1730
1729
|
? context
|
|
1731
|
-
: { 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;
|
|
1732
1733
|
var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
|
|
1733
1734
|
var idToken = context.authMode === "MSAL" ? context.idToken : "";
|
|
1734
1735
|
var _j = useOTPHandler({
|
|
@@ -1738,39 +1739,30 @@ var MFAOptions = function (_a) {
|
|
|
1738
1739
|
appCode: context.appCode || "",
|
|
1739
1740
|
authenticationType: authType,
|
|
1740
1741
|
MFAEndpoint: MFAEndpoint,
|
|
1741
|
-
onAuthComplete: function (state, data) {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
_a.label = 1;
|
|
1749
|
-
case 1:
|
|
1750
|
-
_a.trys.push([1, 3, , 4]);
|
|
1751
|
-
return [4 /*yield*/, completeMFA(lastOTPCode, authType)];
|
|
1752
|
-
case 2:
|
|
1753
|
-
_a.sent();
|
|
1754
|
-
return [3 /*break*/, 4];
|
|
1755
|
-
case 3:
|
|
1756
|
-
error_1 = _a.sent();
|
|
1757
|
-
console.error("Failed to complete MFA:", error_1);
|
|
1758
|
-
return [3 /*break*/, 4];
|
|
1759
|
-
case 4:
|
|
1760
|
-
setShowSuccessAnimation(true);
|
|
1761
|
-
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" })] }));
|
|
1762
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
|
|
1763
|
-
return [3 /*break*/, 6];
|
|
1764
|
-
case 5:
|
|
1765
|
-
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." })] }));
|
|
1766
|
-
if (isMaxAttemptsReached) {
|
|
1767
|
-
setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
|
|
1768
|
-
}
|
|
1769
|
-
_a.label = 6;
|
|
1770
|
-
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
|
+
});
|
|
1771
1749
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
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
|
+
},
|
|
1774
1766
|
}), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
|
|
1775
1767
|
var handleGoBack = function () {
|
|
1776
1768
|
setAuthType(null);
|
|
@@ -1818,18 +1810,18 @@ var MFAOptions = function (_a) {
|
|
|
1818
1810
|
setAuthType(null);
|
|
1819
1811
|
setOtpVisible(false);
|
|
1820
1812
|
setValue("");
|
|
1821
|
-
}, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Email OTP" }) }), jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
|
|
1813
|
+
}, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Email OTP" }) }), jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
|
|
1822
1814
|
setLastOTPCode(code);
|
|
1823
1815
|
return handleSubmitOTP(code);
|
|
1824
1816
|
}, fieldName: "EmailOTP", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] })] }) }));
|
|
1825
1817
|
}
|
|
1826
1818
|
else if (authType === "AuthenticatorCode") {
|
|
1827
|
-
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Authenticator App" }) }), loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 h-full flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(CardDescription, { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
|
|
1819
|
+
content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: jsxRuntimeExports.jsxs(DialogContent, { className: "space-y-2 w-[425px] max-w-[80%]", children: [jsxRuntimeExports.jsx("div", { className: "absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-lime-400 to-emerald-600" }), jsxRuntimeExports.jsx(DialogHeader, { className: "w-full", children: jsxRuntimeExports.jsx(DialogTitle, { className: "text-center", children: "Authenticator App" }) }), loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 h-full flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [jsxRuntimeExports.jsx(CardDescription, { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
|
|
1828
1820
|
setLastOTPCode(code);
|
|
1829
1821
|
return handleSubmitOTP(code);
|
|
1830
1822
|
}, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] }))] }) }));
|
|
1831
1823
|
}
|
|
1832
|
-
return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsxs(Card, { className: "
|
|
1824
|
+
return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsxs(Card, { className: "space-y-6 p-6 rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("div", { className: "flex justify-center items", children: jsxRuntimeExports.jsx("img", { src: OTPAuthenticationImg, alt: "NIBSS Logo", width: 365, height: 365 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold mb-6 text-center", children: "Two-Factor Authentication" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-300 text-base -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { children: content }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }));
|
|
1833
1825
|
};
|
|
1834
1826
|
|
|
1835
1827
|
var LoginButton = function () {
|
|
@@ -1855,6 +1847,7 @@ var MFAGate = function (_a) {
|
|
|
1855
1847
|
if (!urlValidation.success) {
|
|
1856
1848
|
throw new Error("Invalid MFAEndpoint: ".concat(urlValidation.error.issues[0].message));
|
|
1857
1849
|
}
|
|
1850
|
+
console.log("MFA Endpoint >>>", MFAEndpoint);
|
|
1858
1851
|
// Only apply MFA gate for MSAL mode
|
|
1859
1852
|
if (context.authMode !== "MSAL") {
|
|
1860
1853
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
@@ -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, {}));
|