@nibssplc/cams-sdk-react 0.0.1-beta.69 → 0.0.1-beta.71

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
@@ -300,7 +300,7 @@ function useCAMSMSALAuth(options) {
300
300
  setMfaAuthenticator(authenticator);
301
301
  setRequiresMFA(true);
302
302
  }
303
- console.log("App Code >>>", options.appCode);
303
+ camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
304
304
  }
305
305
  else {
306
306
  localStorage.removeItem(storageKey);
@@ -463,6 +463,7 @@ function useCAMSMSALAuth(options) {
463
463
  switch (_a.label) {
464
464
  case 0:
465
465
  _a.trys.push([0, 2, , 3]);
466
+ camsSdk.Logger.info("Logging User Out");
466
467
  return [4 /*yield*/, instance.logoutRedirect()];
467
468
  case 1:
468
469
  _a.sent();
@@ -1214,8 +1215,8 @@ function CAMSProviderCore(props) {
1214
1215
  !auth.requiresMFA &&
1215
1216
  auth.isAuthenticated &&
1216
1217
  !userProfile) {
1217
- // MFA completed, extract profile from stored data
1218
- var storedData = getCookie(auth.storageKey);
1218
+ // MFA completed, extract profile from localStorage
1219
+ var storedData = localStorage.getItem(auth.storageKey);
1219
1220
  if (storedData) {
1220
1221
  try {
1221
1222
  var parsed = JSON.parse(storedData);
@@ -1226,7 +1227,7 @@ function CAMSProviderCore(props) {
1226
1227
  catch (_a) { }
1227
1228
  }
1228
1229
  }
1229
- }, [mode, auth, userProfile]);
1230
+ }, [mode, auth, userProfile, auth.storageKey]);
1230
1231
  var value = React.useMemo(function () {
1231
1232
  return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1232
1233
  }, [auth, userProfile, mode, mode === "MSAL" && "requiresMFA" in auth ? auth.requiresMFA : null]);
@@ -1738,7 +1739,7 @@ var useOTPHandler = function (_a) {
1738
1739
  };
1739
1740
 
1740
1741
  var MFAOptions = function (_a) {
1741
- var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, MFAEndpoint = _b.MFAEndpoint;
1742
+ var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, onAuthFailed = _b.onAuthFailed, MFAEndpoint = _b.MFAEndpoint;
1742
1743
  var _c = React.useState(""), value = _c[0], setValue = _c[1];
1743
1744
  var _d = React.useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1744
1745
  var _e = React.useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
@@ -1747,7 +1748,9 @@ var MFAOptions = function (_a) {
1747
1748
  var context = useCAMSContext();
1748
1749
  var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1749
1750
  ? context
1750
- : { sendEmailOTP: null, completeMFA: null }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA;
1751
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
1752
+ return [2 /*return*/];
1753
+ }); }); } }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA, logout = _h.logout;
1751
1754
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1752
1755
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1753
1756
  var _j = useOTPHandler({
@@ -1757,39 +1760,30 @@ var MFAOptions = function (_a) {
1757
1760
  appCode: context.appCode || "",
1758
1761
  authenticationType: authType,
1759
1762
  MFAEndpoint: MFAEndpoint,
1760
- onAuthComplete: function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
1761
- var error_1;
1762
- return __generator(this, function (_a) {
1763
- switch (_a.label) {
1764
- case 0:
1765
- if (!state) return [3 /*break*/, 5];
1766
- if (!(completeMFA && authType && lastOTPCode)) return [3 /*break*/, 4];
1767
- _a.label = 1;
1768
- case 1:
1769
- _a.trys.push([1, 3, , 4]);
1770
- return [4 /*yield*/, completeMFA(lastOTPCode, authType)];
1771
- case 2:
1772
- _a.sent();
1773
- return [3 /*break*/, 4];
1774
- case 3:
1775
- error_1 = _a.sent();
1776
- console.error("Failed to complete MFA:", error_1);
1777
- return [3 /*break*/, 4];
1778
- case 4:
1779
- setShowSuccessAnimation(true);
1780
- 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" })] }));
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*/];
1763
+ onAuthComplete: function (state, data) {
1764
+ if (state) {
1765
+ // Call completeMFA to update context state
1766
+ if (completeMFA && authType && lastOTPCode) {
1767
+ completeMFA(lastOTPCode, authType).catch(function (error) {
1768
+ console.error("Failed to complete MFA:", error);
1769
+ });
1770
+ }
1771
+ setShowSuccessAnimation(true);
1772
+ 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" })] }));
1773
+ setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1774
+ }
1775
+ else {
1776
+ 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." })] }));
1777
+ if (isMaxAttemptsReached) {
1778
+ setTimeout(function () {
1779
+ logout().then(function () {
1780
+ onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1781
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1782
+ });
1783
+ }, 1000);
1790
1784
  }
1791
- });
1792
- }); },
1785
+ }
1786
+ },
1793
1787
  }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1794
1788
  var handleGoBack = function () {
1795
1789
  setAuthType(null);
@@ -1874,7 +1868,7 @@ var MFAGate = function (_a) {
1874
1868
  if (!urlValidation.success) {
1875
1869
  throw new Error("Invalid MFAEndpoint: ".concat(urlValidation.error.issues[0].message));
1876
1870
  }
1877
- console.log("MFA Endpoint >>>", MFAEndpoint);
1871
+ camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoint: MFAEndpoint });
1878
1872
  // Only apply MFA gate for MSAL mode
1879
1873
  if (context.authMode !== "MSAL") {
1880
1874
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
@@ -1888,7 +1882,16 @@ var MFAGate = function (_a) {
1888
1882
  if (!success) {
1889
1883
  console.error("MFA authentication failed");
1890
1884
  }
1891
- } }));
1885
+ }, onAuthFailed: function () { return __awaiter(void 0, void 0, void 0, function () {
1886
+ return __generator(this, function (_a) {
1887
+ switch (_a.label) {
1888
+ case 0: return [4 /*yield*/, context.logout()];
1889
+ case 1:
1890
+ _a.sent();
1891
+ return [2 /*return*/];
1892
+ }
1893
+ });
1894
+ }); } }));
1892
1895
  }
1893
1896
  if (!isAuthenticated) {
1894
1897
  return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));