@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.
package/dist/index.esm.js CHANGED
@@ -280,7 +280,7 @@ function useCAMSMSALAuth(options) {
280
280
  setMfaAuthenticator(authenticator);
281
281
  setRequiresMFA(true);
282
282
  }
283
- console.log("App Code >>>", options.appCode);
283
+ Logger.debug("App Code", { ">>>": options.appCode });
284
284
  }
285
285
  else {
286
286
  localStorage.removeItem(storageKey);
@@ -443,6 +443,7 @@ function useCAMSMSALAuth(options) {
443
443
  switch (_a.label) {
444
444
  case 0:
445
445
  _a.trys.push([0, 2, , 3]);
446
+ Logger.info("Logging User Out");
446
447
  return [4 /*yield*/, instance.logoutRedirect()];
447
448
  case 1:
448
449
  _a.sent();
@@ -1194,8 +1195,8 @@ function CAMSProviderCore(props) {
1194
1195
  !auth.requiresMFA &&
1195
1196
  auth.isAuthenticated &&
1196
1197
  !userProfile) {
1197
- // MFA completed, extract profile from stored data
1198
- var storedData = getCookie(auth.storageKey);
1198
+ // MFA completed, extract profile from localStorage
1199
+ var storedData = localStorage.getItem(auth.storageKey);
1199
1200
  if (storedData) {
1200
1201
  try {
1201
1202
  var parsed = JSON.parse(storedData);
@@ -1206,7 +1207,7 @@ function CAMSProviderCore(props) {
1206
1207
  catch (_a) { }
1207
1208
  }
1208
1209
  }
1209
- }, [mode, auth, userProfile]);
1210
+ }, [mode, auth, userProfile, auth.storageKey]);
1210
1211
  var value = useMemo(function () {
1211
1212
  return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1212
1213
  }, [auth, userProfile, mode, mode === "MSAL" && "requiresMFA" in auth ? auth.requiresMFA : null]);
@@ -1718,7 +1719,7 @@ var useOTPHandler = function (_a) {
1718
1719
  };
1719
1720
 
1720
1721
  var MFAOptions = function (_a) {
1721
- var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, MFAEndpoint = _b.MFAEndpoint;
1722
+ var _b = _a === void 0 ? {} : _a, onComplete = _b.onComplete, onAuthFailed = _b.onAuthFailed, MFAEndpoint = _b.MFAEndpoint;
1722
1723
  var _c = useState(""), value = _c[0], setValue = _c[1];
1723
1724
  var _d = useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1724
1725
  var _e = useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
@@ -1727,7 +1728,9 @@ var MFAOptions = function (_a) {
1727
1728
  var context = useCAMSContext();
1728
1729
  var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1729
1730
  ? context
1730
- : { sendEmailOTP: null, completeMFA: null }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA;
1731
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
1732
+ return [2 /*return*/];
1733
+ }); }); } }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA, logout = _h.logout;
1731
1734
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1732
1735
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1733
1736
  var _j = useOTPHandler({
@@ -1737,39 +1740,30 @@ var MFAOptions = function (_a) {
1737
1740
  appCode: context.appCode || "",
1738
1741
  authenticationType: authType,
1739
1742
  MFAEndpoint: MFAEndpoint,
1740
- onAuthComplete: function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
1741
- var error_1;
1742
- return __generator(this, function (_a) {
1743
- switch (_a.label) {
1744
- case 0:
1745
- if (!state) return [3 /*break*/, 5];
1746
- if (!(completeMFA && authType && lastOTPCode)) return [3 /*break*/, 4];
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*/];
1743
+ onAuthComplete: function (state, data) {
1744
+ if (state) {
1745
+ // Call completeMFA to update context state
1746
+ if (completeMFA && authType && lastOTPCode) {
1747
+ completeMFA(lastOTPCode, authType).catch(function (error) {
1748
+ console.error("Failed to complete MFA:", error);
1749
+ });
1770
1750
  }
1771
- });
1772
- }); },
1751
+ setShowSuccessAnimation(true);
1752
+ 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" })] }));
1753
+ setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1754
+ }
1755
+ else {
1756
+ 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." })] }));
1757
+ if (isMaxAttemptsReached) {
1758
+ setTimeout(function () {
1759
+ logout().then(function () {
1760
+ onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
1761
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
1762
+ });
1763
+ }, 1000);
1764
+ }
1765
+ }
1766
+ },
1773
1767
  }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1774
1768
  var handleGoBack = function () {
1775
1769
  setAuthType(null);
@@ -1854,7 +1848,7 @@ var MFAGate = function (_a) {
1854
1848
  if (!urlValidation.success) {
1855
1849
  throw new Error("Invalid MFAEndpoint: ".concat(urlValidation.error.issues[0].message));
1856
1850
  }
1857
- console.log("MFA Endpoint >>>", MFAEndpoint);
1851
+ Logger.debug("MFA Endpoint >>>", { MFAEndpoint: MFAEndpoint });
1858
1852
  // Only apply MFA gate for MSAL mode
1859
1853
  if (context.authMode !== "MSAL") {
1860
1854
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
@@ -1868,7 +1862,16 @@ var MFAGate = function (_a) {
1868
1862
  if (!success) {
1869
1863
  console.error("MFA authentication failed");
1870
1864
  }
1871
- } }));
1865
+ }, onAuthFailed: function () { return __awaiter(void 0, void 0, void 0, function () {
1866
+ return __generator(this, function (_a) {
1867
+ switch (_a.label) {
1868
+ case 0: return [4 /*yield*/, context.logout()];
1869
+ case 1:
1870
+ _a.sent();
1871
+ return [2 /*return*/];
1872
+ }
1873
+ });
1874
+ }); } }));
1872
1875
  }
1873
1876
  if (!isAuthenticated) {
1874
1877
  return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));