@nibssplc/cams-sdk-react 1.0.0-rc.62 → 1.0.0-rc.64

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
@@ -18,8 +18,6 @@ var classVarianceAuthority = require('class-variance-authority');
18
18
  var DialogPrimitive = require('@radix-ui/react-dialog');
19
19
  var sonner = require('sonner');
20
20
  var framerMotion = require('framer-motion');
21
- var axios = require('axios');
22
- var https = require('https');
23
21
 
24
22
  function _interopNamespaceDefault(e) {
25
23
  var n = Object.create(null);
@@ -442,8 +440,9 @@ function useCAMSMSALAuth(options) {
442
440
  var _c = React.useState(null), error = _c[0], setError = _c[1];
443
441
  var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
444
442
  var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
445
- var _f = React.useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
446
- var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
443
+ // const [mfaAuthenticator, setMfaAuthenticator] =
444
+ // useState<CAMSMFAAuthenticator | null>(null);
445
+ var _f = React.useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
447
446
  var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
448
447
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
449
448
  var scopes = optScopes || ["openid", "profile", "email"];
@@ -462,22 +461,17 @@ function useCAMSMSALAuth(options) {
462
461
  if (stored) {
463
462
  try {
464
463
  var _a = JSON.parse(stored), accessToken_1 = _a.accessToken, idToken_1 = _a.idToken, storedRequiresMFA = _a.requiresMFA, storedIsAuthenticated = _a.isAuthenticated;
464
+ // Restore MFA state
465
465
  if (accessToken_1 && isTokenValid(accessToken_1)) {
466
466
  setAccessToken(accessToken_1);
467
467
  setIdToken(idToken_1);
468
- // Restore MFA state
469
- if (storedRequiresMFA && !storedIsAuthenticated) {
470
- var mfaConfig = {
471
- accessToken: accessToken_1,
472
- idToken: idToken_1,
473
- appCode: appCode,
474
- provider: "MSAL",
475
- apiEndpoint: MFAEndpoint,
476
- };
477
- var authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
478
- setMfaAuthenticator(authenticator);
479
- setRequiresMFA(true);
480
- }
468
+ setRequiresMFA(storedRequiresMFA);
469
+ camsSdk.Logger.debug("Restored authentication state from storage", {
470
+ accessToken: accessToken_1,
471
+ idToken: idToken_1,
472
+ requiresMFA: storedRequiresMFA,
473
+ isAuthenticated: storedIsAuthenticated,
474
+ });
481
475
  }
482
476
  else {
483
477
  localStorage.removeItem(storageKey);
@@ -491,36 +485,8 @@ function useCAMSMSALAuth(options) {
491
485
  }
492
486
  }
493
487
  }, [accessToken, account, instance, options.storageKey]);
494
- // useEffect(() => {
495
- // const handleRedirect = async () => {
496
- // try {
497
- // const response = await instance.handleRedirectPromise();
498
- // if (response) {
499
- // const account = response.account;
500
- // instance.setActiveA ccount(account);
501
- // const tokenResponse = await instance.acq uireTokenSilent({
502
- // scopes,
503
- // account,
504
- // });
505
- // setToken(tokenResponse.accessToken);
506
- // setAccessToken(tokenResponse.accessToken);
507
- // setIdToken(tokenResponse.idTo ken);
508
- // options.onAuthSuccess?.(tokenR esponse.accessToken);
509
- // if (
510
- // typeof window !== "undefined" &&
511
- // process.env.NODE_ENV !== "test"
512
- // ) {
513
- // window.location.href = options.mfaUrl!;
514
- // }
515
- // }
516
- // } catch (err) {
517
- // console.error("Redirect handling failed:", err);
518
- // }
519
- // };
520
- // handleRedirect();
521
- // }, []);
522
488
  var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
523
- var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
489
+ var response, mfaConfig, authenticator, userConfig, err_1, camsError_1, camsError;
524
490
  var _a;
525
491
  return __generator$1(this, function (_b) {
526
492
  switch (_b.label) {
@@ -532,7 +498,7 @@ function useCAMSMSALAuth(options) {
532
498
  setError(null);
533
499
  _b.label = 1;
534
500
  case 1:
535
- _b.trys.push([1, 3, , 4]);
501
+ _b.trys.push([1, 4, , 5]);
536
502
  return [4 /*yield*/, instance.loginPopup({
537
503
  scopes: scopes,
538
504
  prompt: prompt || "login",
@@ -548,24 +514,27 @@ function useCAMSMSALAuth(options) {
548
514
  mfaConfig = {
549
515
  accessToken: response.accessToken,
550
516
  idToken: response.idToken,
551
- appCode: appCode,
517
+ // appCode,
552
518
  provider: "MSAL",
553
- apiEndpoint: MFAEndpoint,
519
+ APIAuthEndpoint: MFAEndpoint,
554
520
  };
555
- authenticator = new camsSdk.CAMSMFAAuthenticator(mfaConfig);
556
- setMfaAuthenticator(authenticator);
557
- setRequiresMFA(true);
521
+ authenticator = new camsSdk.CAMSMFAAuthenticator();
522
+ return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
523
+ case 3:
524
+ userConfig = _b.sent();
525
+ camsSdk.Logger.info("MFA Authenticator initialized:", userConfig);
526
+ setRequiresMFA(userConfig.userInfo.isMFAEnabled);
558
527
  // Don't persist as authenticated until MFA is complete
559
528
  if (typeof window !== "undefined") {
560
529
  localStorage.setItem(storageKey, JSON.stringify({
561
530
  isAuthenticated: false,
562
- requiresMFA: true,
531
+ requiresMFA: userConfig.userInfo.isMFAEnabled,
563
532
  accessToken: response.accessToken,
564
533
  idToken: response.idToken,
565
534
  }));
566
535
  }
567
- return [3 /*break*/, 4];
568
- case 3:
536
+ return [3 /*break*/, 5];
537
+ case 4:
569
538
  err_1 = _b.sent();
570
539
  // Handle interaction_in_progress error
571
540
  if (err_1.errorCode === "interaction_in_progress") {
@@ -587,24 +556,13 @@ function useCAMSMSALAuth(options) {
587
556
  }
588
557
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
589
558
  setError(camsError);
590
- return [3 /*break*/, 4];
591
- case 4: return [2 /*return*/];
559
+ return [3 /*break*/, 5];
560
+ case 5: return [2 /*return*/];
592
561
  }
593
562
  });
594
- }); }, [
595
- instance,
596
- scopes,
597
- prompt,
598
- appCode,
599
- MFAEndpoint,
600
- storageKey,
601
- inProgress,
602
- ]);
563
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, storageKey, inProgress]);
603
564
  var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
604
565
  return __generator$1(this, function (_a) {
605
- if (!mfaAuthenticator) {
606
- throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
607
- }
608
566
  camsSdk.Logger.info("Completed MFA.. Setting State");
609
567
  try {
610
568
  // Update storage with complete authentication BEFORE setting state
@@ -615,7 +573,7 @@ function useCAMSMSALAuth(options) {
615
573
  accessToken: accessToken,
616
574
  idToken: idToken,
617
575
  }));
618
- setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
576
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ state: "AUTH_SUCCESS", role: data.data.role, profile: __assign({}, data) }), activeCookiePeriod);
619
577
  setRequiresMFA(false);
620
578
  // Set requiresMFA to false after storage update
621
579
  camsSdk.Logger.debug("MFA completed successfully, storage updated", {
@@ -634,19 +592,18 @@ function useCAMSMSALAuth(options) {
634
592
  }
635
593
  return [2 /*return*/];
636
594
  });
637
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
638
- var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
595
+ }); }, [accessToken, idToken, storageKey, activeCookiePeriod]);
596
+ var LoginADCredentials = React.useCallback(function (credentials, appCode, CredentialsAuthEndpoint) { return __awaiter$1(_this, void 0, void 0, function () {
597
+ var authenticator;
639
598
  return __generator$1(this, function (_a) {
640
599
  switch (_a.label) {
641
600
  case 0:
642
- if (!mfaAuthenticator) {
643
- return [2 /*return*/, false];
644
- }
645
- return [4 /*yield*/, mfaAuthenticator.sendEmailOTP()];
601
+ authenticator = new camsSdk.CAMSMFAAuthenticator();
602
+ return [4 /*yield*/, authenticator.LoginADCredentials(credentials, CredentialsAuthEndpoint)];
646
603
  case 1: return [2 /*return*/, _a.sent()];
647
604
  }
648
605
  });
649
- }); }, [mfaAuthenticator]);
606
+ }); }, []);
650
607
  var logout = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
651
608
  var err_2, camsError;
652
609
  return __generator$1(this, function (_a) {
@@ -660,7 +617,6 @@ function useCAMSMSALAuth(options) {
660
617
  setAccessToken("");
661
618
  setIdToken("");
662
619
  setError(null);
663
- setMfaAuthenticator(null);
664
620
  setRequiresMFA(false);
665
621
  if (typeof window !== "undefined") {
666
622
  localStorage.removeItem(storageKey);
@@ -686,10 +642,9 @@ function useCAMSMSALAuth(options) {
686
642
  idToken: idToken,
687
643
  accessToken: accessToken,
688
644
  appCode: appCode,
689
- mfaAuthenticator: mfaAuthenticator,
690
645
  requiresMFA: requiresMFA,
691
646
  completeMFA: completeMFA,
692
- sendEmailOTP: sendEmailOTP,
647
+ LoginADCredentials: LoginADCredentials,
693
648
  setRequiresMFA: setRequiresMFA,
694
649
  activeCookiePeriod: activeCookiePeriod,
695
650
  };
@@ -1070,7 +1025,9 @@ function CAMSProviderCore(props) {
1070
1025
  ]);
1071
1026
  var value = React.useMemo(function () {
1072
1027
  auth.logout; var authRest = __rest(auth, ["logout"]);
1073
- return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
1028
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, user: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL"
1029
+ ? props.onAuthSuccess
1030
+ : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
1074
1031
  }, [auth, userProfile, mode, props]);
1075
1032
  return jsxRuntime.jsx(CAMSContext.Provider, { value: value, children: children });
1076
1033
  }
@@ -1089,7 +1046,7 @@ function UnifiedCAMSProvider(props) {
1089
1046
  var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
1090
1047
  return (jsxRuntime.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntime.jsx(CAMSProviderCore, __assign({}, props)) }));
1091
1048
  }
1092
- return (jsxRuntime.jsx(ClientOnly, { fallback: jsxRuntime.jsx("div", { className: 'h-screen flex items-center justify-center', children: "Loading..." }), children: jsxRuntime.jsx(CAMSProviderCore, __assign({}, props)) }));
1049
+ return (jsxRuntime.jsx(ClientOnly, { fallback: jsxRuntime.jsx("div", { className: "h-screen flex items-center justify-center", children: "Loading..." }), children: jsxRuntime.jsx(CAMSProviderCore, __assign({}, props)) }));
1093
1050
  }
1094
1051
  // Backward compatibility exports
1095
1052
  var CAMSProvider = function (props) { return (jsxRuntime.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
@@ -1428,79 +1385,14 @@ var AuthSuccessAnimation = function (_a) {
1428
1385
  return (jsxRuntime.jsxs(framerMotion.motion.div, { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, transition: { duration: 0.5, ease: "easeOut" }, className: "flex flex-col items-center justify-center space-y-6 p-8", onAnimationComplete: onComplete, children: [jsxRuntime.jsx(framerMotion.motion.div, { initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.2, duration: 0.6, type: "spring", stiffness: 200 }, children: jsxRuntime.jsx(lucideReact.CheckCircle, { className: "w-20 h-20 text-green-500" }) }), jsxRuntime.jsxs(framerMotion.motion.div, { initial: { y: 20, opacity: 0 }, animate: { y: 0, opacity: 1 }, transition: { delay: 0.4, duration: 0.5 }, className: "text-center space-y-2", children: [jsxRuntime.jsx("h2", { className: "text-2xl font-bold text-green-600", children: "Authentication Successful!" }), jsxRuntime.jsx("p", { className: "text-gray-600", children: "Redirecting you to the application..." })] }), jsxRuntime.jsx(framerMotion.motion.div, { initial: { width: 0 }, animate: { width: "100%" }, transition: { delay: 0.8, duration: 2 }, className: "h-1 bg-green-500 rounded-full max-w-xs" })] }));
1429
1386
  };
1430
1387
 
1431
- // Function to parse userAgent and generate a device ID
1432
- var GenerateDeviceId = function () {
1433
- var _a;
1434
- if (typeof window === "undefined" || !window.navigator) {
1435
- return "unknown-device";
1436
- }
1437
- var userAgent = window.navigator.userAgent;
1438
- var deviceId = "";
1439
- // Parse browser, version, OS, and device type
1440
- var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
1441
- var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
1442
- var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
1443
- // Browser info
1444
- if (browserMatch.length > 0) {
1445
- var _b = browserMatch[0], browserName = _b[1], browserVersion = _b[2];
1446
- var majorVersion = browserVersion.split(".")[0];
1447
- deviceId += "".concat(browserName, "-").concat(majorVersion);
1448
- }
1449
- else {
1450
- deviceId += "UnknownBrowser";
1451
- }
1452
- // OS info
1453
- if (osMatch.length > 0) {
1454
- var osInfo = osMatch[0][1]
1455
- .split(";")[0]
1456
- .trim()
1457
- .replace(/[\s/()]/g, "_");
1458
- deviceId += "_".concat(osInfo);
1459
- }
1460
- else {
1461
- deviceId += "_UnknownOS";
1462
- }
1463
- // Device type
1464
- deviceId += isMobile ? "_Mobile" : "_Desktop";
1465
- // Add a simple hash of userAgent for uniqueness
1466
- var hash = btoa(userAgent).slice(0, 8);
1467
- deviceId += "_".concat(hash);
1468
- return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
1469
- };
1470
- var APIHeaders = {
1471
- "X-DEVICE-ID": GenerateDeviceId(),
1472
- "X-API-VERSION": "1.0",
1473
- };
1474
-
1475
- // Creates an Axios instance with a base URL determined by the environment (production or development).
1476
- var axiosInstance = axios.create({
1477
- httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1478
- headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1479
- });
1480
- // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1481
- axiosInstance.interceptors.request.use(function (config) {
1482
- var _a;
1483
- config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1484
- config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1485
- return config; // Returns the modified request configuration.
1486
- }, function (axiosError) {
1487
- var _a, _b;
1488
- // Handles request errors.
1489
- return {
1490
- status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1491
- message: axiosError.message, // Extracts the error message.
1492
- data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1493
- };
1494
- });
1495
-
1496
1388
  var MAX_ATTEMPTS = 3;
1497
1389
  var useOTPHandler = function (_a) {
1498
- var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1390
+ var email = _a.email, appCode = _a.appCode, instCode = _a.instCode, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1499
1391
  var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
1500
1392
  var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1501
1393
  var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1502
1394
  var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1503
- var currentAttempt, response, error_1, currentAttempt;
1395
+ var currentAttempt, authentication, response, error_1, currentAttempt;
1504
1396
  return __generator$1(this, function (_a) {
1505
1397
  switch (_a.label) {
1506
1398
  case 0:
@@ -1516,18 +1408,15 @@ var useOTPHandler = function (_a) {
1516
1408
  setLoading(true);
1517
1409
  currentAttempt = attemptCount + 1;
1518
1410
  setAttemptCount(currentAttempt);
1519
- if (authenticationType === null)
1520
- return [2 /*return*/, false];
1521
- return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1522
- provider: provider,
1523
- accessToken: accessToken,
1524
- idToken: idToken,
1525
- authenticationType: authenticationType,
1526
- MFACode: authenticationValue,
1411
+ authentication = new camsSdk.CAMSMFAAuthenticator();
1412
+ return [4 /*yield*/, authentication.VerifyMFAOTP({
1527
1413
  appCode: appCode,
1528
- })];
1414
+ instCode: instCode,
1415
+ email: email,
1416
+ MFACode: authenticationValue,
1417
+ }, MFAEndpoint || "")];
1529
1418
  case 2:
1530
- response = (_a.sent()).data;
1419
+ response = _a.sent();
1531
1420
  if (response) {
1532
1421
  onAuthComplete(true, response);
1533
1422
  return [2 /*return*/, true];
@@ -1563,15 +1452,7 @@ var useOTPHandler = function (_a) {
1563
1452
  case 5: return [2 /*return*/];
1564
1453
  }
1565
1454
  });
1566
- }); }; }, [
1567
- accessToken,
1568
- idToken,
1569
- authenticationType,
1570
- onAuthComplete,
1571
- MFAEndpoint,
1572
- attemptCount,
1573
- isMaxAttemptsReached,
1574
- ]);
1455
+ }); }; }, [onAuthComplete, MFAEndpoint, attemptCount, isMaxAttemptsReached]);
1575
1456
  var resetAttempts = React.useCallback(function () {
1576
1457
  setAttemptCount(0);
1577
1458
  setIsMaxAttemptsReached(false);
@@ -1591,8 +1472,8 @@ var useCredentialsHandler = function (onAuthComplete) {
1591
1472
  var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1592
1473
  var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1593
1474
  var handleSubmitCredentials = React.useMemo(function () {
1594
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1595
- var currentAttempt, response, error_2, currentAttempt;
1475
+ return function (CredentialsAuthEndpoint, credentials) { return __awaiter$1(void 0, void 0, void 0, function () {
1476
+ var currentAttempt, authenticator, response, error_2, currentAttempt;
1596
1477
  return __generator$1(this, function (_a) {
1597
1478
  switch (_a.label) {
1598
1479
  case 0:
@@ -1600,14 +1481,24 @@ var useCredentialsHandler = function (onAuthComplete) {
1600
1481
  setLoading(true);
1601
1482
  currentAttempt = attemptCount + 1;
1602
1483
  setAttemptCount(currentAttempt);
1603
- return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1604
- username: credentials.username,
1605
- password: credentials.password,
1606
- MFACode: credentials.MFACode,
1607
- appCode: appCode,
1608
- })];
1484
+ authenticator = new camsSdk.CAMSMFAAuthenticator();
1485
+ return [4 /*yield*/, authenticator.LoginADCredentials(credentials, CredentialsAuthEndpoint)];
1609
1486
  case 1:
1610
- response = (_a.sent()).data;
1487
+ response = _a.sent();
1488
+ // .then((data) => {
1489
+ // context.isAuthenticated = true;
1490
+ // (context as any).requiresMFA = false;
1491
+ // context.setUserProfile({
1492
+ // type: "AUTH_SUCCESS",
1493
+ // userProfile: {
1494
+ // ...data,
1495
+ // },
1496
+ // });
1497
+ // })
1498
+ // .catch((error) => {
1499
+ // console.error("AD Login failed:", error);
1500
+ // toast.error("❌ AD Login failed.");
1501
+ // });
1611
1502
  if (response) {
1612
1503
  onAuthComplete(true, response);
1613
1504
  return [2 /*return*/, true];
@@ -1657,60 +1548,56 @@ var useCredentialsHandler = function (onAuthComplete) {
1657
1548
  };
1658
1549
 
1659
1550
  var MFAOptions = function (_a) {
1551
+ var _b, _c;
1660
1552
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
1661
- var _b = React.useState(""), value = _b[0], setValue = _b[1];
1662
- var _c = React.useState(false), otpVisible = _c[0], setOtpVisible = _c[1];
1663
- var _d = React.useState(false), showSuccessAnimation = _d[0], setShowSuccessAnimation = _d[1];
1664
- var _e = React.useState(null), authType = _e[0], setAuthType = _e[1];
1553
+ var _d = React.useState(""), value = _d[0], setValue = _d[1];
1554
+ var _e = React.useState(false), otpVisible = _e[0], setOtpVisible = _e[1];
1555
+ var _f = React.useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
1556
+ var _g = React.useState(null), authType = _g[0], setAuthType = _g[1];
1665
1557
  var context = useCAMSContext();
1666
- var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1558
+ var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1667
1559
  ? context
1668
1560
  : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1669
1561
  return [2 /*return*/];
1670
- }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1671
- var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1672
- var idToken = context.authMode === "MSAL" ? context.idToken : "";
1562
+ }); }); } }; _h.sendEmailOTP; var completeMFA = _h.completeMFA, logout = _h.logout;
1563
+ context.authMode === "MSAL" ? context.accessToken : "";
1564
+ context.authMode === "MSAL" ? context.idToken : "";
1673
1565
  var authenticate = useWebAuthn().authenticate;
1674
- var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1675
- var options, assertionResponse, error_1;
1676
- return __generator$1(this, function (_a) {
1677
- switch (_a.label) {
1678
- case 0:
1679
- _a.trys.push([0, 4, , 5]);
1680
- // 1. Fetch authentication challenge from your server
1681
- console.log("Requesting authentication challenge from server...");
1682
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1683
- case 1:
1684
- options = (_a.sent()).data;
1685
- console.log("Received challenge:", options);
1686
- // 2. Call the SDK to trigger the browser's passkey authentication UI
1687
- console.log("Calling SDK authenticate function...");
1688
- return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
1689
- case 2:
1690
- assertionResponse = _a.sent();
1691
- console.log("Authentication assertion received from client:", assertionResponse);
1692
- // 3. Send the assertion back to the server for verification
1693
- console.log("Sending assertion to server for verification...");
1694
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1695
- case 3:
1696
- _a.sent();
1697
- sonner.toast.success("🔑 Sign-in successful!");
1698
- return [3 /*break*/, 5];
1699
- case 4:
1700
- error_1 = _a.sent();
1701
- console.error("Authentication failed:", error_1);
1702
- sonner.toast.error(" Could not sign in.");
1703
- return [3 /*break*/, 5];
1704
- case 5: return [2 /*return*/];
1705
- }
1706
- });
1707
- }); };
1708
- var _g = useOTPHandler({
1709
- accessToken: accessToken || "",
1710
- idToken: idToken || "",
1711
- provider: "MSAL",
1566
+ var authenticator = new camsSdk.CAMSMFAAuthenticator();
1567
+ // const handleFIDOLogin = async () => {
1568
+ // try {
1569
+ // // 1. Fetch authentication challenge from your server
1570
+ // console.log("Requesting authentication challenge from server...");
1571
+ // const { data: options } = await axiosInstance.post(
1572
+ // MFAEndpoints.RetrieveAuthChallenge,
1573
+ // {}
1574
+ // );
1575
+ // console.log("Received challenge:", options);
1576
+ // // 2. Call the SDK to trigger the browser's passkey authentication UI
1577
+ // console.log("Calling SDK authenticate function...");
1578
+ // const assertionResponse = await authenticate({
1579
+ // ...options,
1580
+ // userVerification: "discouraged",
1581
+ // });
1582
+ // console.log(
1583
+ // "Authentication assertion received from client:",
1584
+ // assertionResponse
1585
+ // );
1586
+ // // 3. Send the assertion back to the server for verification
1587
+ // console.log("Sending assertion to server for verification...");
1588
+ // await axiosInstance.post(
1589
+ // MFAEndpoints.AuthChallengeVerify,
1590
+ // assertionResponse
1591
+ // );
1592
+ // toast.success("🔑 Sign-in successful!");
1593
+ // } catch (error) {
1594
+ // console.error("Authentication failed:", error);
1595
+ // toast.error("❌ Could not sign in.");
1596
+ // }
1597
+ // };
1598
+ var _j = useOTPHandler({
1599
+ email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || "",
1712
1600
  appCode: context.appCode || "",
1713
- authenticationType: authType,
1714
1601
  MFAEndpoint: MFAEndpoints.ValidateMFA,
1715
1602
  onAuthComplete: function (state, data) {
1716
1603
  console.log("Completed Auth. Handling MFA", state);
@@ -1738,7 +1625,7 @@ var MFAOptions = function (_a) {
1738
1625
  }
1739
1626
  }
1740
1627
  },
1741
- }), handleSubmitOTP = _g.handleSubmitOTP, loading = _g.loading, setLoading = _g.setLoading, attemptCount = _g.attemptCount, remainingAttempts = _g.remainingAttempts, isMaxAttemptsReached = _g.isMaxAttemptsReached, resetAttempts = _g.resetAttempts;
1628
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1742
1629
  var handleGoBack = function () {
1743
1630
  setAuthType(null);
1744
1631
  setOtpVisible(false);
@@ -1753,28 +1640,7 @@ var MFAOptions = function (_a) {
1753
1640
  }
1754
1641
  var content = jsxRuntime.jsx(jsxRuntime.Fragment, {});
1755
1642
  if (!authType) {
1756
- content = (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [jsxRuntime.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () { return __awaiter$1(void 0, void 0, void 0, function () {
1757
- var success;
1758
- return __generator$1(this, function (_a) {
1759
- switch (_a.label) {
1760
- case 0:
1761
- // resetAttempts();
1762
- setAuthType("EmailOTP");
1763
- setOtpVisible(true);
1764
- if (!sendEmailOTP) return [3 /*break*/, 2];
1765
- setLoading(true);
1766
- return [4 /*yield*/, sendEmailOTP()];
1767
- case 1:
1768
- success = _a.sent();
1769
- setLoading(false);
1770
- if (success) {
1771
- sonner.toast.success(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4" }), jsxRuntime.jsx("span", { children: "OTP sent to your email address" })] }));
1772
- }
1773
- _a.label = 2;
1774
- case 2: return [2 /*return*/];
1775
- }
1776
- });
1777
- }); }, children: [jsxRuntime.jsx(lucideReact.Mail, { className: "w-5 h-5" }), jsxRuntime.jsxs("div", { className: "text-left", children: [jsxRuntime.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntime.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntime.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
1643
+ content = (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [jsxRuntime.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all", onClick: function () {
1778
1644
  setAuthType("AuthenticatorCode");
1779
1645
  setOtpVisible(true);
1780
1646
  }, children: [jsxRuntime.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntime.jsx(lucideReact.Shield, {}); } }), jsxRuntime.jsxs("div", { className: "text-left", children: [jsxRuntime.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntime.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntime.jsxs(Button, { variant: "outline", className: "w-full flex items-center justify-start gap-3 p-4 h-auto border-2 hover:border-[#506f4a] hover:bg-[#506f4a]/5 transition-all",
@@ -1783,7 +1649,9 @@ var MFAOptions = function (_a) {
1783
1649
  // setAuthType("AuthenticatorCode");
1784
1650
  // setOtpVisible(true);
1785
1651
  // }}
1786
- onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntime.jsxs("div", { className: "text-left", children: [jsxRuntime.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntime.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
1652
+ onClick: function () {
1653
+ return authenticator.HandleFIDOLogin(MFAEndpoints.RetrieveAuthChallenge, MFAEndpoints.AuthChallengeVerify, authenticate);
1654
+ }, disabled: context.isLoading, children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntime.jsxs("div", { className: "text-left", children: [jsxRuntime.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntime.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
1787
1655
  }
1788
1656
  else if (authType === "EmailOTP") {
1789
1657
  content = (jsxRuntime.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -1846,6 +1714,7 @@ var ADLoginModal = function (_a) {
1846
1714
  username: credentials.username,
1847
1715
  password: credentials.password,
1848
1716
  MFACode: code,
1717
+ appCode: "",
1849
1718
  })];
1850
1719
  case 2:
1851
1720
  _a.sent();
@@ -1871,17 +1740,17 @@ var ADLoginModal = function (_a) {
1871
1740
  form.reset();
1872
1741
  setMfaCode("");
1873
1742
  };
1874
- return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntime.jsx(Form, __assign({}, form, { children: jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntime.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1743
+ return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "credentials" ? (jsxRuntime.jsx(Form, __assign({}, form, { children: jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsxRuntime.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1875
1744
  var field = _a.field;
1876
1745
  return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Username" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
1877
1746
  } }), jsxRuntime.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
1878
1747
  var field = _a.field;
1879
1748
  return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Password" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
1880
- } }), jsxRuntime.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntime.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1749
+ } }), jsxRuntime.jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntime.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1881
1750
  };
1882
1751
 
1883
1752
  var DefaultLoginPage = function (_a) {
1884
- var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
1753
+ var _b = _a.username, username = _b === void 0 ? "" : _b, usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
1885
1754
  var cardVariants = {
1886
1755
  hidden: { opacity: 0, scale: 0.8, y: 50 },
1887
1756
  visible: {
@@ -1894,22 +1763,31 @@ var DefaultLoginPage = function (_a) {
1894
1763
  };
1895
1764
  var context = useCAMSContext();
1896
1765
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1897
- var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
1766
+ var _c = React.useState(false), showADModal = _c[0], setShowADModal = _c[1];
1898
1767
  var register = useWebAuthn().register;
1899
- var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1768
+ var authentication = new camsSdk.CAMSMFAAuthenticator();
1769
+ var _d = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1900
1770
  return __generator$1(this, function (_a) {
1901
1771
  console.log(data);
1902
- if (state && data) {
1772
+ if (state && data && data.isValid) {
1903
1773
  context.isAuthenticated = true;
1904
1774
  context.requiresMFA = false;
1905
1775
  context.setUserProfile({
1906
- type: "AUTH_SUCCESS",
1907
- userProfile: __assign({}, data),
1776
+ state: "AUTH_SUCCESS",
1777
+ role: data.data.role,
1778
+ profile: {
1779
+ id: data.data.id,
1780
+ name: data.data.name,
1781
+ email: data.data.email,
1782
+ isMFAEnabled: data.data.isMFAEnabled,
1783
+ message: data.message,
1784
+ tokens: data.tokens,
1785
+ },
1908
1786
  });
1909
1787
  }
1910
1788
  return [2 /*return*/];
1911
1789
  });
1912
- }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
1790
+ }); }), handleSubmitCredentials = _d.handleSubmitCredentials, isCredAuthLoading = _d.loading, setIsCredAuthLoading = _d.setLoading;
1913
1791
  var handleMSALLogin = function () {
1914
1792
  if (typeof window !== "undefined" && !window.crypto) {
1915
1793
  sonner.toast.error("Crypto API not available. Please use a modern browser.");
@@ -1923,53 +1801,21 @@ var DefaultLoginPage = function (_a) {
1923
1801
  console.warn("Regular CAMS login requires configuration");
1924
1802
  }
1925
1803
  };
1926
- var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
1927
- var options, attestationResponse, error_1;
1928
- return __generator$1(this, function (_a) {
1929
- switch (_a.label) {
1930
- case 0:
1931
- _a.trys.push([0, 4, , 5]);
1932
- // 1. Fetch challenge from your server
1933
- console.log("Requesting registration challenge from server...");
1934
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
1935
- case 1:
1936
- options = (_a.sent()).data;
1937
- console.log("Received challenge:", options);
1938
- // 2. Call the SDK to trigger the browser's passkey creation UI
1939
- console.log("Calling SDK register function...");
1940
- return [4 /*yield*/, register(options)];
1941
- case 2:
1942
- attestationResponse = _a.sent();
1943
- console.log("Passkey created on client:", attestationResponse);
1944
- // 3. Send the response back to the server for verification
1945
- console.log("Sending attestation to server for verification...");
1946
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
1947
- case 3:
1948
- _a.sent();
1949
- sonner.toast.success("✅ Registration successful! Passkey created.");
1950
- return [3 /*break*/, 5];
1951
- case 4:
1952
- error_1 = _a.sent();
1953
- console.error("Registration failed:", error_1);
1954
- sonner.toast.error("❌ Could not create passkey.");
1955
- return [3 /*break*/, 5];
1956
- case 5: return [2 /*return*/];
1957
- }
1958
- });
1959
- }); };
1960
- 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: 265, height: 265 }) }), 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
1804
+ 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
1961
1805
  // variant="outline"
1962
1806
  , {
1963
1807
  // variant="outline"
1964
1808
  className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: handleMSALLogin, disabled: isLoading, children: [jsxRuntime.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntime.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntime.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntime.jsx("span", { children: isLoading
1965
1809
  ? "Logging in..."
1966
- : "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntime.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return handleRegister(PassKeysRegisterProps); }, disabled: isLoading, children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntime.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntime.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntime.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntime.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
1810
+ : "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntime.jsxs(Button, { className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () {
1811
+ return authentication.HandleRegister(MFAEndpoints.RegisterNewChallenge, MFAEndpoints.RegisterVerify +
1812
+ "?username=".concat(username), register, PassKeysRegisterProps);
1813
+ }, disabled: isLoading, children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntime.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntime.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntime.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntime.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
1967
1814
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
1968
1815
  return __generator$1(this, function (_c) {
1969
1816
  // Implement your AD login logic here
1970
- console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
1971
- // Example: await adLoginService(username, password, mfaCode);
1972
- handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
1817
+ console.log("AD Login:", { username: username, MFACode: MFACode });
1818
+ handleSubmitCredentials(CredentialsAuthEndpoint, { username: username, password: password, MFACode: MFACode, appCode: context.appCode });
1973
1819
  return [2 /*return*/];
1974
1820
  });
1975
1821
  }); } })] }));
@@ -1988,7 +1834,7 @@ var MFAEndpointsSchema = z.object({
1988
1834
  AuthChallengeVerify: z.url("MFA AuthChallengeVerify must be a valid URL"),
1989
1835
  });
1990
1836
  var MFAGate = function (_a) {
1991
- var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntime.jsx("div", { className: 'h-screen flex items-center justify-center', children: jsxRuntime.jsx(LoadingSpinner, {}) }) : _b,
1837
+ var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? (jsxRuntime.jsx("div", { className: "h-screen flex items-center justify-center", children: jsxRuntime.jsx(LoadingSpinner, {}) })) : _b,
1992
1838
  // loginComponent: LoginComponent = DefaultLoginPage,
1993
1839
  _c = _a.usePassKey,
1994
1840
  // loginComponent: LoginComponent = DefaultLoginPage,
@@ -2016,7 +1862,7 @@ var MFAGate = function (_a) {
2016
1862
  }
2017
1863
  }
2018
1864
  else if (!success) {
2019
- camsSdk.Logger.error("MFA authentication failed");
1865
+ camsSdk.Logger.error("MFA authentication failed", { context: context || null });
2020
1866
  }
2021
1867
  }, [context, onAuthSuccess]);
2022
1868
  var handleAuthFailed = React.useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
@@ -2037,6 +1883,14 @@ var MFAGate = function (_a) {
2037
1883
  }
2038
1884
  });
2039
1885
  }); }, [context, onAuthError]);
1886
+ React.useEffect(function () {
1887
+ if (requiresMFA === false &&
1888
+ "accessToken" in context &&
1889
+ context.accessToken &&
1890
+ "setRequiresMFA" in context) {
1891
+ context.setRequiresMFA(false);
1892
+ }
1893
+ }, [requiresMFA, context]);
2040
1894
  if (useADLogin && !CredentialsAuthEndpoint)
2041
1895
  return jsxRuntime.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2042
1896
  if (!validatedMFAEndpoints)
@@ -2048,11 +1902,6 @@ var MFAGate = function (_a) {
2048
1902
  if (!context.isAuthenticated) {
2049
1903
  var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : ("requiresMFA" in context ? context.requiresMFA : false);
2050
1904
  var accessToken = "accessToken" in context ? context.accessToken : "";
2051
- // If requiresMFA is explicitly set to false, bypass MFA and mark as authenticated
2052
- if (requiresMFA === false && accessToken && "setRequiresMFA" in context) {
2053
- context.setRequiresMFA(false);
2054
- return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
2055
- }
2056
1905
  if (shouldRequireMFA && accessToken) {
2057
1906
  return (jsxRuntime.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2058
1907
  }