@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.esm.js CHANGED
@@ -421,7 +421,8 @@ function useCAMSMSALAuth(options) {
421
421
  var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
422
422
  var _f = useState(""), email = _f[0], setEmail = _f[1];
423
423
  var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
424
- var isLoading = inProgress !== InteractionStatus.None;
424
+ var _h = useState(false), isFetchingMFAConfig = _h[0], setIsFetchingMFAConfig = _h[1];
425
+ var isLoading = inProgress !== InteractionStatus.None || isFetchingMFAConfig;
425
426
  var isAuthenticated = !!account && !!accessToken;
426
427
  var scopes = optScopes || ["openid", "profile", "email"];
427
428
  var isTokenValid = function (token) {
@@ -490,9 +491,11 @@ function useCAMSMSALAuth(options) {
490
491
  APIAuthEndpoint: ValidateUserEndpoint,
491
492
  };
492
493
  authenticator = new CAMSMFAAuthenticator();
494
+ setIsFetchingMFAConfig(true);
493
495
  return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
494
496
  case 3:
495
497
  userConfig = _b.sent();
498
+ setIsFetchingMFAConfig(false);
496
499
  console.log("CAMS MFA Authenticator initialized:", {
497
500
  mfaConfig: mfaConfig,
498
501
  userConfig: userConfig,
@@ -519,6 +522,7 @@ function useCAMSMSALAuth(options) {
519
522
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + userConfig.message);
520
523
  toast.error("Login failed");
521
524
  setError(camsError);
525
+ setIsFetchingMFAConfig(false);
522
526
  }
523
527
  return [3 /*break*/, 5];
524
528
  case 4:
@@ -543,6 +547,7 @@ function useCAMSMSALAuth(options) {
543
547
  }
544
548
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
545
549
  setError(camsError);
550
+ setIsFetchingMFAConfig(false);
546
551
  return [3 /*break*/, 5];
547
552
  case 5: return [2 /*return*/];
548
553
  }
@@ -1530,29 +1535,22 @@ var useCredentialsHandler = function (onAuthComplete) {
1530
1535
  };
1531
1536
 
1532
1537
  var MFAOptions = function (_a) {
1533
- var _b, _c, _d, _e, _f;
1538
+ var _b, _c;
1534
1539
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
1535
- var _g = useState(""), value = _g[0], setValue = _g[1];
1536
- var _h = useState(false), otpVisible = _h[0], setOtpVisible = _h[1];
1537
- var _j = useState(false), showSuccessAnimation = _j[0], setShowSuccessAnimation = _j[1];
1538
- var _k = useState(null), authType = _k[0], setAuthType = _k[1];
1540
+ var _d = useState(""), value = _d[0], setValue = _d[1];
1541
+ var _e = useState(false), otpVisible = _e[0], setOtpVisible = _e[1];
1542
+ var _f = useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
1543
+ var _g = useState(null), authType = _g[0], setAuthType = _g[1];
1539
1544
  var context = useCAMSContext();
1540
- var _l = context.authMode === "MSAL" && "sendEmailOTP" in context
1545
+ var _h = context.authMode === "MSAL" && "AuthenticatorCode" in context
1541
1546
  ? context
1542
1547
  : { completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1543
1548
  return [2 /*return*/];
1544
- }); }); } }, completeMFA = _l.completeMFA, logout = _l.logout;
1545
- context.authMode === "MSAL" ? context.accessToken : "";
1546
- context.authMode === "MSAL" ? context.idToken : "";
1549
+ }); }); } }, completeMFA = _h.completeMFA, logout = _h.logout;
1547
1550
  var authenticate = useWebAuthn().authenticate;
1548
1551
  var authenticator = new CAMSMFAAuthenticator();
1549
- Logger.debug("User context:", {
1550
- user: context.user,
1551
- profile: (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile,
1552
- email: (_d = (_c = context.user) === null || _c === void 0 ? void 0 : _c.profile) === null || _d === void 0 ? void 0 : _d.email,
1553
- });
1554
- var _m = useOTPHandler({
1555
- email: ((_f = (_e = context.user) === null || _e === void 0 ? void 0 : _e.profile) === null || _f === void 0 ? void 0 : _f.email) || context.email,
1552
+ var _j = useOTPHandler({
1553
+ email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || context.email,
1556
1554
  appCode: context.appCode || "",
1557
1555
  MFAEndpoint: MFAEndpoints.ValidateUserMFA,
1558
1556
  onAuthComplete: function (state, data) {
@@ -1581,7 +1579,7 @@ var MFAOptions = function (_a) {
1581
1579
  }
1582
1580
  }
1583
1581
  },
1584
- }), handleSubmitOTP = _m.handleSubmitOTP, loading = _m.loading, attemptCount = _m.attemptCount, remainingAttempts = _m.remainingAttempts, isMaxAttemptsReached = _m.isMaxAttemptsReached, resetAttempts = _m.resetAttempts;
1582
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1585
1583
  var handleGoBack = function () {
1586
1584
  setAuthType(null);
1587
1585
  setOtpVisible(false);
@@ -1722,20 +1720,20 @@ var DefaultLoginPage = function (_a) {
1722
1720
  var context = useCAMSContext();
1723
1721
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1724
1722
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
1723
+ var _c = useState(false), showSuccessAnimation = _c[0], setShowSuccessAnimation = _c[1];
1725
1724
  var register = useWebAuthn().register;
1726
1725
  var authentication = new CAMSMFAAuthenticator();
1727
- var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1726
+ var _d = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1728
1727
  return __generator$1(this, function (_a) {
1729
1728
  console.log(data);
1730
1729
  if (state && data && data.isValid) {
1731
- context.isAuthenticated = true;
1730
+ setShowSuccessAnimation(true);
1732
1731
  localStorage.setItem(context.storageKey, JSON.stringify({
1733
- isAuthenticated: false,
1732
+ isAuthenticated: true,
1734
1733
  requiresMFA: false,
1735
1734
  accessToken: "Credentials",
1736
1735
  idToken: "Credentials",
1737
1736
  }));
1738
- context.requiresMFA = false;
1739
1737
  context.setUserProfile({
1740
1738
  state: "AUTH_SUCCESS",
1741
1739
  message: data.message,
@@ -1748,13 +1746,14 @@ var DefaultLoginPage = function (_a) {
1748
1746
  tokens: data.tokens,
1749
1747
  },
1750
1748
  });
1749
+ setShowADModal(false);
1751
1750
  }
1752
1751
  else {
1753
1752
  toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
1754
1753
  }
1755
1754
  return [2 /*return*/];
1756
1755
  });
1757
- }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
1756
+ }); }), handleSubmitCredentials = _d.handleSubmitCredentials, isCredAuthLoading = _d.loading, setIsCredAuthLoading = _d.setLoading;
1758
1757
  var handleMSALLogin = function () {
1759
1758
  if (typeof window !== "undefined" && !window.crypto) {
1760
1759
  toast.error("Crypto API not available. Please use a modern browser.");
@@ -1768,6 +1767,11 @@ var DefaultLoginPage = function (_a) {
1768
1767
  console.warn("Regular CAMS login requires configuration");
1769
1768
  }
1770
1769
  };
1770
+ if (showSuccessAnimation && useADLogin) {
1771
+ return (jsx("div", { className: "flex justify-center items-center h-dvh", children: jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsx(AuthSuccessAnimation, { onComplete: function () {
1772
+ // Animation completed, can add additional logic here if needed
1773
+ } }) }) }));
1774
+ }
1771
1775
  return (jsxs("main", { className: "cams-sdk min-h-screen bg-gray-50", children: [jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsx("div", { className: "flex h-screen items-center justify-center", children: jsxs(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: [jsxs(CardHeader, { className: "text-center space-y-3", children: [jsx("div", { className: "w-full flex items-center justify-center", children: jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 225, height: 225 }) }), jsx(CardTitle, { className: "text-3xl font-bold", children: "NIBSS CAMS" }), jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxs("div", { className: "space-y-4", children: [jsxs(Button
1772
1776
  // variant="outline"
1773
1777
  , {
@@ -1836,6 +1840,8 @@ var MFAGate = function (_a) {
1836
1840
  (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
1837
1841
  }
1838
1842
  }
1843
+ // Force state update after MFA completion
1844
+ setAuthState("Authenticated");
1839
1845
  }
1840
1846
  else if (!success) {
1841
1847
  Logger.error("MFA authentication failed", { context: context || null });