@nibssplc/cams-sdk-react 1.0.0-rc.83 → 1.0.0-rc.85

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.cjs.js CHANGED
@@ -442,7 +442,8 @@ function useCAMSMSALAuth(options) {
442
442
  var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
443
443
  var _f = React.useState(""), email = _f[0], setEmail = _f[1];
444
444
  var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
445
- var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
445
+ var _h = React.useState(false), isFetchingMFAConfig = _h[0], setIsFetchingMFAConfig = _h[1];
446
+ var isLoading = inProgress !== msalBrowser.InteractionStatus.None || isFetchingMFAConfig;
446
447
  var isAuthenticated = !!account && !!accessToken;
447
448
  var scopes = optScopes || ["openid", "profile", "email"];
448
449
  var isTokenValid = function (token) {
@@ -511,9 +512,11 @@ function useCAMSMSALAuth(options) {
511
512
  APIAuthEndpoint: ValidateUserEndpoint,
512
513
  };
513
514
  authenticator = new camsSdk.CAMSMFAAuthenticator();
515
+ setIsFetchingMFAConfig(true);
514
516
  return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
515
517
  case 3:
516
518
  userConfig = _b.sent();
519
+ setIsFetchingMFAConfig(false);
517
520
  console.log("CAMS MFA Authenticator initialized:", {
518
521
  mfaConfig: mfaConfig,
519
522
  userConfig: userConfig,
@@ -540,6 +543,7 @@ function useCAMSMSALAuth(options) {
540
543
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + userConfig.message);
541
544
  sonner.toast.error("Login failed");
542
545
  setError(camsError);
546
+ setIsFetchingMFAConfig(false);
543
547
  }
544
548
  return [3 /*break*/, 5];
545
549
  case 4:
@@ -564,6 +568,7 @@ function useCAMSMSALAuth(options) {
564
568
  }
565
569
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
566
570
  setError(camsError);
571
+ setIsFetchingMFAConfig(false);
567
572
  return [3 /*break*/, 5];
568
573
  case 5: return [2 /*return*/];
569
574
  }
@@ -1551,29 +1556,22 @@ var useCredentialsHandler = function (onAuthComplete) {
1551
1556
  };
1552
1557
 
1553
1558
  var MFAOptions = function (_a) {
1554
- var _b, _c, _d, _e, _f;
1559
+ var _b, _c;
1555
1560
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
1556
- var _g = React.useState(""), value = _g[0], setValue = _g[1];
1557
- var _h = React.useState(false), otpVisible = _h[0], setOtpVisible = _h[1];
1558
- var _j = React.useState(false), showSuccessAnimation = _j[0], setShowSuccessAnimation = _j[1];
1559
- var _k = React.useState(null), authType = _k[0], setAuthType = _k[1];
1561
+ var _d = React.useState(""), value = _d[0], setValue = _d[1];
1562
+ var _e = React.useState(false), otpVisible = _e[0], setOtpVisible = _e[1];
1563
+ var _f = React.useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
1564
+ var _g = React.useState(null), authType = _g[0], setAuthType = _g[1];
1560
1565
  var context = useCAMSContext();
1561
- var _l = context.authMode === "MSAL" && "sendEmailOTP" in context
1566
+ var _h = context.authMode === "MSAL" && "AuthenticatorCode" in context
1562
1567
  ? context
1563
1568
  : { completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1564
1569
  return [2 /*return*/];
1565
- }); }); } }, completeMFA = _l.completeMFA, logout = _l.logout;
1566
- context.authMode === "MSAL" ? context.accessToken : "";
1567
- context.authMode === "MSAL" ? context.idToken : "";
1570
+ }); }); } }, completeMFA = _h.completeMFA, logout = _h.logout;
1568
1571
  var authenticate = useWebAuthn().authenticate;
1569
1572
  var authenticator = new camsSdk.CAMSMFAAuthenticator();
1570
- camsSdk.Logger.debug("User context:", {
1571
- user: context.user,
1572
- profile: (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile,
1573
- email: (_d = (_c = context.user) === null || _c === void 0 ? void 0 : _c.profile) === null || _d === void 0 ? void 0 : _d.email,
1574
- });
1575
- var _m = useOTPHandler({
1576
- email: ((_f = (_e = context.user) === null || _e === void 0 ? void 0 : _e.profile) === null || _f === void 0 ? void 0 : _f.email) || context.email,
1573
+ var _j = useOTPHandler({
1574
+ email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || context.email,
1577
1575
  appCode: context.appCode || "",
1578
1576
  MFAEndpoint: MFAEndpoints.ValidateUserMFA,
1579
1577
  onAuthComplete: function (state, data) {
@@ -1602,7 +1600,7 @@ var MFAOptions = function (_a) {
1602
1600
  }
1603
1601
  }
1604
1602
  },
1605
- }), handleSubmitOTP = _m.handleSubmitOTP, loading = _m.loading, attemptCount = _m.attemptCount, remainingAttempts = _m.remainingAttempts, isMaxAttemptsReached = _m.isMaxAttemptsReached, resetAttempts = _m.resetAttempts;
1603
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1606
1604
  var handleGoBack = function () {
1607
1605
  setAuthType(null);
1608
1606
  setOtpVisible(false);
@@ -1743,20 +1741,20 @@ var DefaultLoginPage = function (_a) {
1743
1741
  var context = useCAMSContext();
1744
1742
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1745
1743
  var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
1744
+ var _c = React.useState(false), showSuccessAnimation = _c[0], setShowSuccessAnimation = _c[1];
1746
1745
  var register = useWebAuthn().register;
1747
1746
  var authentication = new camsSdk.CAMSMFAAuthenticator();
1748
- var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1747
+ var _d = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1749
1748
  return __generator$1(this, function (_a) {
1750
1749
  console.log(data);
1751
1750
  if (state && data && data.isValid) {
1752
- context.isAuthenticated = true;
1751
+ setShowSuccessAnimation(true);
1753
1752
  localStorage.setItem(context.storageKey, JSON.stringify({
1754
- isAuthenticated: false,
1753
+ isAuthenticated: true,
1755
1754
  requiresMFA: false,
1756
1755
  accessToken: "Credentials",
1757
1756
  idToken: "Credentials",
1758
1757
  }));
1759
- context.requiresMFA = false;
1760
1758
  context.setUserProfile({
1761
1759
  state: "AUTH_SUCCESS",
1762
1760
  message: data.message,
@@ -1769,13 +1767,14 @@ var DefaultLoginPage = function (_a) {
1769
1767
  tokens: data.tokens,
1770
1768
  },
1771
1769
  });
1770
+ setShowADModal(false);
1772
1771
  }
1773
1772
  else {
1774
1773
  sonner.toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
1775
1774
  }
1776
1775
  return [2 /*return*/];
1777
1776
  });
1778
- }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
1777
+ }); }), handleSubmitCredentials = _d.handleSubmitCredentials, isCredAuthLoading = _d.loading, setIsCredAuthLoading = _d.setLoading;
1779
1778
  var handleMSALLogin = function () {
1780
1779
  if (typeof window !== "undefined" && !window.crypto) {
1781
1780
  sonner.toast.error("Crypto API not available. Please use a modern browser.");
@@ -1789,6 +1788,11 @@ var DefaultLoginPage = function (_a) {
1789
1788
  console.warn("Regular CAMS login requires configuration");
1790
1789
  }
1791
1790
  };
1791
+ if (showSuccessAnimation && useADLogin) {
1792
+ return (jsxRuntime.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntime.jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsxRuntime.jsx(AuthSuccessAnimation, { onComplete: function () {
1793
+ // Animation completed, can add additional logic here if needed
1794
+ } }) }) }));
1795
+ }
1792
1796
  return (jsxRuntime.jsxs("main", { className: "cams-sdk min-h-screen bg-gray-50", children: [jsxRuntime.jsx(framerMotion.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntime.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntime.jsxs(framerMotion.motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 rounded-2xl shadow-2xl", children: [jsxRuntime.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntime.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntime.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 225, height: 225 }) }), jsxRuntime.jsx(CardTitle, { className: "text-3xl font-bold", children: "NIBSS CAMS" }), jsxRuntime.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntime.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntime.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsxs(Button
1793
1797
  // variant="outline"
1794
1798
  , {
@@ -1857,6 +1861,8 @@ var MFAGate = function (_a) {
1857
1861
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1858
1862
  }
1859
1863
  }
1864
+ // Force state update after MFA completion
1865
+ setAuthState("Authenticated");
1860
1866
  }
1861
1867
  else if (!success) {
1862
1868
  camsSdk.Logger.error("MFA authentication failed", { context: context || null });