@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.
@@ -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
@@ -301,7 +301,6 @@ function useCAMSMSALAuth(options) {
301
301
  setRequiresMFA(true);
302
302
  }
303
303
  console.log("App Code >>>", options.appCode);
304
- console.log("MFA Endpoint >>>", options.MFAEndpoint);
305
304
  }
306
305
  else {
307
306
  localStorage.removeItem(storageKey);
@@ -1739,7 +1738,7 @@ var useOTPHandler = function (_a) {
1739
1738
  };
1740
1739
 
1741
1740
  var MFAOptions = function (_a) {
1742
- 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;
1743
1742
  var _c = React.useState(""), value = _c[0], setValue = _c[1];
1744
1743
  var _d = React.useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1745
1744
  var _e = React.useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
@@ -1748,7 +1747,9 @@ var MFAOptions = function (_a) {
1748
1747
  var context = useCAMSContext();
1749
1748
  var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1750
1749
  ? context
1751
- : { sendEmailOTP: null, completeMFA: null }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA;
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;
1752
1753
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1753
1754
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1754
1755
  var _j = useOTPHandler({
@@ -1758,39 +1759,30 @@ var MFAOptions = function (_a) {
1758
1759
  appCode: context.appCode || "",
1759
1760
  authenticationType: authType,
1760
1761
  MFAEndpoint: MFAEndpoint,
1761
- onAuthComplete: function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
1762
- var error_1;
1763
- return __generator(this, function (_a) {
1764
- switch (_a.label) {
1765
- case 0:
1766
- if (!state) return [3 /*break*/, 5];
1767
- if (!(completeMFA && authType && lastOTPCode)) return [3 /*break*/, 4];
1768
- _a.label = 1;
1769
- case 1:
1770
- _a.trys.push([1, 3, , 4]);
1771
- return [4 /*yield*/, completeMFA(lastOTPCode, authType)];
1772
- case 2:
1773
- _a.sent();
1774
- return [3 /*break*/, 4];
1775
- case 3:
1776
- error_1 = _a.sent();
1777
- console.error("Failed to complete MFA:", error_1);
1778
- return [3 /*break*/, 4];
1779
- case 4:
1780
- setShowSuccessAnimation(true);
1781
- 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" })] }));
1782
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1783
- return [3 /*break*/, 6];
1784
- case 5:
1785
- 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." })] }));
1786
- if (isMaxAttemptsReached) {
1787
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
1788
- }
1789
- _a.label = 6;
1790
- 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);
1791
1783
  }
1792
- });
1793
- }); },
1784
+ }
1785
+ },
1794
1786
  }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1795
1787
  var handleGoBack = function () {
1796
1788
  setAuthType(null);
@@ -1838,18 +1830,18 @@ var MFAOptions = function (_a) {
1838
1830
  setAuthType(null);
1839
1831
  setOtpVisible(false);
1840
1832
  setValue("");
1841
- }, 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) {
1833
+ }, 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) {
1842
1834
  setLastOTPCode(code);
1843
1835
  return handleSubmitOTP(code);
1844
1836
  }, 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" })] })] }) }));
1845
1837
  }
1846
1838
  else if (authType === "AuthenticatorCode") {
1847
- 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) {
1839
+ 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) {
1848
1840
  setLastOTPCode(code);
1849
1841
  return handleSubmitOTP(code);
1850
1842
  }, 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" })] }))] }) }));
1851
1843
  }
1852
- return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsxs(Card, { className: "mx-auto sm:max-w-[425px] max-w-[80%] space-y-6 p-6 bg-white 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(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }));
1844
+ 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(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }));
1853
1845
  };
1854
1846
 
1855
1847
  var LoginButton = function () {
@@ -1875,6 +1867,7 @@ var MFAGate = function (_a) {
1875
1867
  if (!urlValidation.success) {
1876
1868
  throw new Error("Invalid MFAEndpoint: ".concat(urlValidation.error.issues[0].message));
1877
1869
  }
1870
+ console.log("MFA Endpoint >>>", MFAEndpoint);
1878
1871
  // Only apply MFA gate for MSAL mode
1879
1872
  if (context.authMode !== "MSAL") {
1880
1873
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
@@ -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, {}));