@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.esm.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import { useState, useRef, useEffect, useCallback, createContext, useContext, useMemo } from 'react';
3
- import { CAMSSessionManager, isPopupWindow, CAMSMFAAuthenticator, Logger, CAMSError, CAMSErrorType } from '@nibssplc/cams-sdk';
3
+ import { CAMSSessionManager, isPopupWindow, Logger, CAMSError, CAMSErrorType, CAMSMFAAuthenticator } from '@nibssplc/cams-sdk';
4
4
  export * from '@nibssplc/cams-sdk';
5
5
  import { useMsal, useAccount, MsalProvider } from '@azure/msal-react';
6
6
  import { InteractionStatus, PublicClientApplication } from '@azure/msal-browser';
7
7
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
8
8
  import z$1, { z } from 'zod';
9
9
  import { OTPInput, OTPInputContext, REGEXP_ONLY_DIGITS } from 'input-otp';
10
- import { RectangleEllipsis, XIcon, CheckCircle, Mail, Shield, KeyIcon, ShieldCheck, ShieldClose, Loader2 } from 'lucide-react';
10
+ import { RectangleEllipsis, XIcon, CheckCircle, Shield, KeyIcon, ShieldCheck, ShieldClose, Loader2 } from 'lucide-react';
11
11
  import { appendErrors, FormProvider, Controller, useFormContext, useFormState, useForm } from 'react-hook-form';
12
12
  import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
13
13
  import { clsx } from 'clsx';
@@ -18,8 +18,6 @@ import { cva } from 'class-variance-authority';
18
18
  import * as DialogPrimitive from '@radix-ui/react-dialog';
19
19
  import { toast } from 'sonner';
20
20
  import { motion } from 'framer-motion';
21
- import axios from 'axios';
22
- import https from 'https';
23
21
 
24
22
  /******************************************************************************
25
23
  Copyright (c) Microsoft Corporation.
@@ -421,8 +419,9 @@ function useCAMSMSALAuth(options) {
421
419
  var _c = useState(null), error = _c[0], setError = _c[1];
422
420
  var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
423
421
  var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
424
- var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
425
- var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
422
+ // const [mfaAuthenticator, setMfaAuthenticator] =
423
+ // useState<CAMSMFAAuthenticator | null>(null);
424
+ var _f = useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
426
425
  var isLoading = inProgress !== InteractionStatus.None;
427
426
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
428
427
  var scopes = optScopes || ["openid", "profile", "email"];
@@ -441,22 +440,17 @@ function useCAMSMSALAuth(options) {
441
440
  if (stored) {
442
441
  try {
443
442
  var _a = JSON.parse(stored), accessToken_1 = _a.accessToken, idToken_1 = _a.idToken, storedRequiresMFA = _a.requiresMFA, storedIsAuthenticated = _a.isAuthenticated;
443
+ // Restore MFA state
444
444
  if (accessToken_1 && isTokenValid(accessToken_1)) {
445
445
  setAccessToken(accessToken_1);
446
446
  setIdToken(idToken_1);
447
- // Restore MFA state
448
- if (storedRequiresMFA && !storedIsAuthenticated) {
449
- var mfaConfig = {
450
- accessToken: accessToken_1,
451
- idToken: idToken_1,
452
- appCode: appCode,
453
- provider: "MSAL",
454
- apiEndpoint: MFAEndpoint,
455
- };
456
- var authenticator = new CAMSMFAAuthenticator(mfaConfig);
457
- setMfaAuthenticator(authenticator);
458
- setRequiresMFA(true);
459
- }
447
+ setRequiresMFA(storedRequiresMFA);
448
+ Logger.debug("Restored authentication state from storage", {
449
+ accessToken: accessToken_1,
450
+ idToken: idToken_1,
451
+ requiresMFA: storedRequiresMFA,
452
+ isAuthenticated: storedIsAuthenticated,
453
+ });
460
454
  }
461
455
  else {
462
456
  localStorage.removeItem(storageKey);
@@ -470,36 +464,8 @@ function useCAMSMSALAuth(options) {
470
464
  }
471
465
  }
472
466
  }, [accessToken, account, instance, options.storageKey]);
473
- // useEffect(() => {
474
- // const handleRedirect = async () => {
475
- // try {
476
- // const response = await instance.handleRedirectPromise();
477
- // if (response) {
478
- // const account = response.account;
479
- // instance.setActiveA ccount(account);
480
- // const tokenResponse = await instance.acq uireTokenSilent({
481
- // scopes,
482
- // account,
483
- // });
484
- // setToken(tokenResponse.accessToken);
485
- // setAccessToken(tokenResponse.accessToken);
486
- // setIdToken(tokenResponse.idTo ken);
487
- // options.onAuthSuccess?.(tokenR esponse.accessToken);
488
- // if (
489
- // typeof window !== "undefined" &&
490
- // process.env.NODE_ENV !== "test"
491
- // ) {
492
- // window.location.href = options.mfaUrl!;
493
- // }
494
- // }
495
- // } catch (err) {
496
- // console.error("Redirect handling failed:", err);
497
- // }
498
- // };
499
- // handleRedirect();
500
- // }, []);
501
467
  var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
502
- var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
468
+ var response, mfaConfig, authenticator, userConfig, err_1, camsError_1, camsError;
503
469
  var _a;
504
470
  return __generator$1(this, function (_b) {
505
471
  switch (_b.label) {
@@ -511,7 +477,7 @@ function useCAMSMSALAuth(options) {
511
477
  setError(null);
512
478
  _b.label = 1;
513
479
  case 1:
514
- _b.trys.push([1, 3, , 4]);
480
+ _b.trys.push([1, 4, , 5]);
515
481
  return [4 /*yield*/, instance.loginPopup({
516
482
  scopes: scopes,
517
483
  prompt: prompt || "login",
@@ -527,24 +493,27 @@ function useCAMSMSALAuth(options) {
527
493
  mfaConfig = {
528
494
  accessToken: response.accessToken,
529
495
  idToken: response.idToken,
530
- appCode: appCode,
496
+ // appCode,
531
497
  provider: "MSAL",
532
- apiEndpoint: MFAEndpoint,
498
+ APIAuthEndpoint: MFAEndpoint,
533
499
  };
534
- authenticator = new CAMSMFAAuthenticator(mfaConfig);
535
- setMfaAuthenticator(authenticator);
536
- setRequiresMFA(true);
500
+ authenticator = new CAMSMFAAuthenticator();
501
+ return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
502
+ case 3:
503
+ userConfig = _b.sent();
504
+ Logger.info("MFA Authenticator initialized:", userConfig);
505
+ setRequiresMFA(userConfig.userInfo.isMFAEnabled);
537
506
  // Don't persist as authenticated until MFA is complete
538
507
  if (typeof window !== "undefined") {
539
508
  localStorage.setItem(storageKey, JSON.stringify({
540
509
  isAuthenticated: false,
541
- requiresMFA: true,
510
+ requiresMFA: userConfig.userInfo.isMFAEnabled,
542
511
  accessToken: response.accessToken,
543
512
  idToken: response.idToken,
544
513
  }));
545
514
  }
546
- return [3 /*break*/, 4];
547
- case 3:
515
+ return [3 /*break*/, 5];
516
+ case 4:
548
517
  err_1 = _b.sent();
549
518
  // Handle interaction_in_progress error
550
519
  if (err_1.errorCode === "interaction_in_progress") {
@@ -566,24 +535,13 @@ function useCAMSMSALAuth(options) {
566
535
  }
567
536
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
568
537
  setError(camsError);
569
- return [3 /*break*/, 4];
570
- case 4: return [2 /*return*/];
538
+ return [3 /*break*/, 5];
539
+ case 5: return [2 /*return*/];
571
540
  }
572
541
  });
573
- }); }, [
574
- instance,
575
- scopes,
576
- prompt,
577
- appCode,
578
- MFAEndpoint,
579
- storageKey,
580
- inProgress,
581
- ]);
542
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, storageKey, inProgress]);
582
543
  var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
583
544
  return __generator$1(this, function (_a) {
584
- if (!mfaAuthenticator) {
585
- throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
586
- }
587
545
  Logger.info("Completed MFA.. Setting State");
588
546
  try {
589
547
  // Update storage with complete authentication BEFORE setting state
@@ -594,7 +552,7 @@ function useCAMSMSALAuth(options) {
594
552
  accessToken: accessToken,
595
553
  idToken: idToken,
596
554
  }));
597
- setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
555
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ state: "AUTH_SUCCESS", role: data.data.role, profile: __assign({}, data) }), activeCookiePeriod);
598
556
  setRequiresMFA(false);
599
557
  // Set requiresMFA to false after storage update
600
558
  Logger.debug("MFA completed successfully, storage updated", {
@@ -613,19 +571,18 @@ function useCAMSMSALAuth(options) {
613
571
  }
614
572
  return [2 /*return*/];
615
573
  });
616
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
617
- var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
574
+ }); }, [accessToken, idToken, storageKey, activeCookiePeriod]);
575
+ var LoginADCredentials = useCallback(function (credentials, appCode, CredentialsAuthEndpoint) { return __awaiter$1(_this, void 0, void 0, function () {
576
+ var authenticator;
618
577
  return __generator$1(this, function (_a) {
619
578
  switch (_a.label) {
620
579
  case 0:
621
- if (!mfaAuthenticator) {
622
- return [2 /*return*/, false];
623
- }
624
- return [4 /*yield*/, mfaAuthenticator.sendEmailOTP()];
580
+ authenticator = new CAMSMFAAuthenticator();
581
+ return [4 /*yield*/, authenticator.LoginADCredentials(credentials, CredentialsAuthEndpoint)];
625
582
  case 1: return [2 /*return*/, _a.sent()];
626
583
  }
627
584
  });
628
- }); }, [mfaAuthenticator]);
585
+ }); }, []);
629
586
  var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
630
587
  var err_2, camsError;
631
588
  return __generator$1(this, function (_a) {
@@ -639,7 +596,6 @@ function useCAMSMSALAuth(options) {
639
596
  setAccessToken("");
640
597
  setIdToken("");
641
598
  setError(null);
642
- setMfaAuthenticator(null);
643
599
  setRequiresMFA(false);
644
600
  if (typeof window !== "undefined") {
645
601
  localStorage.removeItem(storageKey);
@@ -665,10 +621,9 @@ function useCAMSMSALAuth(options) {
665
621
  idToken: idToken,
666
622
  accessToken: accessToken,
667
623
  appCode: appCode,
668
- mfaAuthenticator: mfaAuthenticator,
669
624
  requiresMFA: requiresMFA,
670
625
  completeMFA: completeMFA,
671
- sendEmailOTP: sendEmailOTP,
626
+ LoginADCredentials: LoginADCredentials,
672
627
  setRequiresMFA: setRequiresMFA,
673
628
  activeCookiePeriod: activeCookiePeriod,
674
629
  };
@@ -1049,7 +1004,9 @@ function CAMSProviderCore(props) {
1049
1004
  ]);
1050
1005
  var value = useMemo(function () {
1051
1006
  auth.logout; var authRest = __rest(auth, ["logout"]);
1052
- return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
1007
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, user: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL"
1008
+ ? props.onAuthSuccess
1009
+ : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
1053
1010
  }, [auth, userProfile, mode, props]);
1054
1011
  return jsx(CAMSContext.Provider, { value: value, children: children });
1055
1012
  }
@@ -1068,7 +1025,7 @@ function UnifiedCAMSProvider(props) {
1068
1025
  var instance = msalInstance || new PublicClientApplication(msalConfig);
1069
1026
  return (jsx(MsalProvider, { instance: instance, children: jsx(CAMSProviderCore, __assign({}, props)) }));
1070
1027
  }
1071
- return (jsx(ClientOnly, { fallback: jsx("div", { className: 'h-screen flex items-center justify-center', children: "Loading..." }), children: jsx(CAMSProviderCore, __assign({}, props)) }));
1028
+ return (jsx(ClientOnly, { fallback: jsx("div", { className: "h-screen flex items-center justify-center", children: "Loading..." }), children: jsx(CAMSProviderCore, __assign({}, props)) }));
1072
1029
  }
1073
1030
  // Backward compatibility exports
1074
1031
  var CAMSProvider = function (props) { return (jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
@@ -1407,79 +1364,14 @@ var AuthSuccessAnimation = function (_a) {
1407
1364
  return (jsxs(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: [jsx(motion.div, { initial: { scale: 0 }, animate: { scale: 1 }, transition: { delay: 0.2, duration: 0.6, type: "spring", stiffness: 200 }, children: jsx(CheckCircle, { className: "w-20 h-20 text-green-500" }) }), jsxs(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: [jsx("h2", { className: "text-2xl font-bold text-green-600", children: "Authentication Successful!" }), jsx("p", { className: "text-gray-600", children: "Redirecting you to the application..." })] }), jsx(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" })] }));
1408
1365
  };
1409
1366
 
1410
- // Function to parse userAgent and generate a device ID
1411
- var GenerateDeviceId = function () {
1412
- var _a;
1413
- if (typeof window === "undefined" || !window.navigator) {
1414
- return "unknown-device";
1415
- }
1416
- var userAgent = window.navigator.userAgent;
1417
- var deviceId = "";
1418
- // Parse browser, version, OS, and device type
1419
- var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
1420
- var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
1421
- var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
1422
- // Browser info
1423
- if (browserMatch.length > 0) {
1424
- var _b = browserMatch[0], browserName = _b[1], browserVersion = _b[2];
1425
- var majorVersion = browserVersion.split(".")[0];
1426
- deviceId += "".concat(browserName, "-").concat(majorVersion);
1427
- }
1428
- else {
1429
- deviceId += "UnknownBrowser";
1430
- }
1431
- // OS info
1432
- if (osMatch.length > 0) {
1433
- var osInfo = osMatch[0][1]
1434
- .split(";")[0]
1435
- .trim()
1436
- .replace(/[\s/()]/g, "_");
1437
- deviceId += "_".concat(osInfo);
1438
- }
1439
- else {
1440
- deviceId += "_UnknownOS";
1441
- }
1442
- // Device type
1443
- deviceId += isMobile ? "_Mobile" : "_Desktop";
1444
- // Add a simple hash of userAgent for uniqueness
1445
- var hash = btoa(userAgent).slice(0, 8);
1446
- deviceId += "_".concat(hash);
1447
- return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
1448
- };
1449
- var APIHeaders = {
1450
- "X-DEVICE-ID": GenerateDeviceId(),
1451
- "X-API-VERSION": "1.0",
1452
- };
1453
-
1454
- // Creates an Axios instance with a base URL determined by the environment (production or development).
1455
- var axiosInstance = axios.create({
1456
- httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1457
- headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1458
- });
1459
- // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1460
- axiosInstance.interceptors.request.use(function (config) {
1461
- var _a;
1462
- config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1463
- config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1464
- return config; // Returns the modified request configuration.
1465
- }, function (axiosError) {
1466
- var _a, _b;
1467
- // Handles request errors.
1468
- return {
1469
- status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1470
- message: axiosError.message, // Extracts the error message.
1471
- data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1472
- };
1473
- });
1474
-
1475
1367
  var MAX_ATTEMPTS = 3;
1476
1368
  var useOTPHandler = function (_a) {
1477
- var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1369
+ var email = _a.email, appCode = _a.appCode, instCode = _a.instCode, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1478
1370
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
1479
1371
  var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1480
1372
  var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1481
1373
  var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1482
- var currentAttempt, response, error_1, currentAttempt;
1374
+ var currentAttempt, authentication, response, error_1, currentAttempt;
1483
1375
  return __generator$1(this, function (_a) {
1484
1376
  switch (_a.label) {
1485
1377
  case 0:
@@ -1495,18 +1387,15 @@ var useOTPHandler = function (_a) {
1495
1387
  setLoading(true);
1496
1388
  currentAttempt = attemptCount + 1;
1497
1389
  setAttemptCount(currentAttempt);
1498
- if (authenticationType === null)
1499
- return [2 /*return*/, false];
1500
- return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1501
- provider: provider,
1502
- accessToken: accessToken,
1503
- idToken: idToken,
1504
- authenticationType: authenticationType,
1505
- MFACode: authenticationValue,
1390
+ authentication = new CAMSMFAAuthenticator();
1391
+ return [4 /*yield*/, authentication.VerifyMFAOTP({
1506
1392
  appCode: appCode,
1507
- })];
1393
+ instCode: instCode,
1394
+ email: email,
1395
+ MFACode: authenticationValue,
1396
+ }, MFAEndpoint || "")];
1508
1397
  case 2:
1509
- response = (_a.sent()).data;
1398
+ response = _a.sent();
1510
1399
  if (response) {
1511
1400
  onAuthComplete(true, response);
1512
1401
  return [2 /*return*/, true];
@@ -1542,15 +1431,7 @@ var useOTPHandler = function (_a) {
1542
1431
  case 5: return [2 /*return*/];
1543
1432
  }
1544
1433
  });
1545
- }); }; }, [
1546
- accessToken,
1547
- idToken,
1548
- authenticationType,
1549
- onAuthComplete,
1550
- MFAEndpoint,
1551
- attemptCount,
1552
- isMaxAttemptsReached,
1553
- ]);
1434
+ }); }; }, [onAuthComplete, MFAEndpoint, attemptCount, isMaxAttemptsReached]);
1554
1435
  var resetAttempts = useCallback(function () {
1555
1436
  setAttemptCount(0);
1556
1437
  setIsMaxAttemptsReached(false);
@@ -1570,8 +1451,8 @@ var useCredentialsHandler = function (onAuthComplete) {
1570
1451
  var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1571
1452
  var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1572
1453
  var handleSubmitCredentials = useMemo(function () {
1573
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1574
- var currentAttempt, response, error_2, currentAttempt;
1454
+ return function (CredentialsAuthEndpoint, credentials) { return __awaiter$1(void 0, void 0, void 0, function () {
1455
+ var currentAttempt, authenticator, response, error_2, currentAttempt;
1575
1456
  return __generator$1(this, function (_a) {
1576
1457
  switch (_a.label) {
1577
1458
  case 0:
@@ -1579,14 +1460,24 @@ var useCredentialsHandler = function (onAuthComplete) {
1579
1460
  setLoading(true);
1580
1461
  currentAttempt = attemptCount + 1;
1581
1462
  setAttemptCount(currentAttempt);
1582
- return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1583
- username: credentials.username,
1584
- password: credentials.password,
1585
- MFACode: credentials.MFACode,
1586
- appCode: appCode,
1587
- })];
1463
+ authenticator = new CAMSMFAAuthenticator();
1464
+ return [4 /*yield*/, authenticator.LoginADCredentials(credentials, CredentialsAuthEndpoint)];
1588
1465
  case 1:
1589
- response = (_a.sent()).data;
1466
+ response = _a.sent();
1467
+ // .then((data) => {
1468
+ // context.isAuthenticated = true;
1469
+ // (context as any).requiresMFA = false;
1470
+ // context.setUserProfile({
1471
+ // type: "AUTH_SUCCESS",
1472
+ // userProfile: {
1473
+ // ...data,
1474
+ // },
1475
+ // });
1476
+ // })
1477
+ // .catch((error) => {
1478
+ // console.error("AD Login failed:", error);
1479
+ // toast.error("❌ AD Login failed.");
1480
+ // });
1590
1481
  if (response) {
1591
1482
  onAuthComplete(true, response);
1592
1483
  return [2 /*return*/, true];
@@ -1636,60 +1527,56 @@ var useCredentialsHandler = function (onAuthComplete) {
1636
1527
  };
1637
1528
 
1638
1529
  var MFAOptions = function (_a) {
1530
+ var _b, _c;
1639
1531
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
1640
- var _b = useState(""), value = _b[0], setValue = _b[1];
1641
- var _c = useState(false), otpVisible = _c[0], setOtpVisible = _c[1];
1642
- var _d = useState(false), showSuccessAnimation = _d[0], setShowSuccessAnimation = _d[1];
1643
- var _e = useState(null), authType = _e[0], setAuthType = _e[1];
1532
+ var _d = useState(""), value = _d[0], setValue = _d[1];
1533
+ var _e = useState(false), otpVisible = _e[0], setOtpVisible = _e[1];
1534
+ var _f = useState(false), showSuccessAnimation = _f[0], setShowSuccessAnimation = _f[1];
1535
+ var _g = useState(null), authType = _g[0], setAuthType = _g[1];
1644
1536
  var context = useCAMSContext();
1645
- var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1537
+ var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1646
1538
  ? context
1647
1539
  : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1648
1540
  return [2 /*return*/];
1649
- }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1650
- var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1651
- var idToken = context.authMode === "MSAL" ? context.idToken : "";
1541
+ }); }); } }; _h.sendEmailOTP; var completeMFA = _h.completeMFA, logout = _h.logout;
1542
+ context.authMode === "MSAL" ? context.accessToken : "";
1543
+ context.authMode === "MSAL" ? context.idToken : "";
1652
1544
  var authenticate = useWebAuthn().authenticate;
1653
- var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1654
- var options, assertionResponse, error_1;
1655
- return __generator$1(this, function (_a) {
1656
- switch (_a.label) {
1657
- case 0:
1658
- _a.trys.push([0, 4, , 5]);
1659
- // 1. Fetch authentication challenge from your server
1660
- console.log("Requesting authentication challenge from server...");
1661
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1662
- case 1:
1663
- options = (_a.sent()).data;
1664
- console.log("Received challenge:", options);
1665
- // 2. Call the SDK to trigger the browser's passkey authentication UI
1666
- console.log("Calling SDK authenticate function...");
1667
- return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
1668
- case 2:
1669
- assertionResponse = _a.sent();
1670
- console.log("Authentication assertion received from client:", assertionResponse);
1671
- // 3. Send the assertion back to the server for verification
1672
- console.log("Sending assertion to server for verification...");
1673
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1674
- case 3:
1675
- _a.sent();
1676
- toast.success("🔑 Sign-in successful!");
1677
- return [3 /*break*/, 5];
1678
- case 4:
1679
- error_1 = _a.sent();
1680
- console.error("Authentication failed:", error_1);
1681
- toast.error(" Could not sign in.");
1682
- return [3 /*break*/, 5];
1683
- case 5: return [2 /*return*/];
1684
- }
1685
- });
1686
- }); };
1687
- var _g = useOTPHandler({
1688
- accessToken: accessToken || "",
1689
- idToken: idToken || "",
1690
- provider: "MSAL",
1545
+ var authenticator = new CAMSMFAAuthenticator();
1546
+ // const handleFIDOLogin = async () => {
1547
+ // try {
1548
+ // // 1. Fetch authentication challenge from your server
1549
+ // console.log("Requesting authentication challenge from server...");
1550
+ // const { data: options } = await axiosInstance.post(
1551
+ // MFAEndpoints.RetrieveAuthChallenge,
1552
+ // {}
1553
+ // );
1554
+ // console.log("Received challenge:", options);
1555
+ // // 2. Call the SDK to trigger the browser's passkey authentication UI
1556
+ // console.log("Calling SDK authenticate function...");
1557
+ // const assertionResponse = await authenticate({
1558
+ // ...options,
1559
+ // userVerification: "discouraged",
1560
+ // });
1561
+ // console.log(
1562
+ // "Authentication assertion received from client:",
1563
+ // assertionResponse
1564
+ // );
1565
+ // // 3. Send the assertion back to the server for verification
1566
+ // console.log("Sending assertion to server for verification...");
1567
+ // await axiosInstance.post(
1568
+ // MFAEndpoints.AuthChallengeVerify,
1569
+ // assertionResponse
1570
+ // );
1571
+ // toast.success("🔑 Sign-in successful!");
1572
+ // } catch (error) {
1573
+ // console.error("Authentication failed:", error);
1574
+ // toast.error("❌ Could not sign in.");
1575
+ // }
1576
+ // };
1577
+ var _j = useOTPHandler({
1578
+ email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || "",
1691
1579
  appCode: context.appCode || "",
1692
- authenticationType: authType,
1693
1580
  MFAEndpoint: MFAEndpoints.ValidateMFA,
1694
1581
  onAuthComplete: function (state, data) {
1695
1582
  console.log("Completed Auth. Handling MFA", state);
@@ -1717,7 +1604,7 @@ var MFAOptions = function (_a) {
1717
1604
  }
1718
1605
  }
1719
1606
  },
1720
- }), handleSubmitOTP = _g.handleSubmitOTP, loading = _g.loading, setLoading = _g.setLoading, attemptCount = _g.attemptCount, remainingAttempts = _g.remainingAttempts, isMaxAttemptsReached = _g.isMaxAttemptsReached, resetAttempts = _g.resetAttempts;
1607
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1721
1608
  var handleGoBack = function () {
1722
1609
  setAuthType(null);
1723
1610
  setOtpVisible(false);
@@ -1732,28 +1619,7 @@ var MFAOptions = function (_a) {
1732
1619
  }
1733
1620
  var content = jsx(Fragment, {});
1734
1621
  if (!authType) {
1735
- content = (jsxs("div", { className: "space-y-4", children: [jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxs("div", { className: "flex flex-col gap-3", children: [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 () {
1736
- var success;
1737
- return __generator$1(this, function (_a) {
1738
- switch (_a.label) {
1739
- case 0:
1740
- // resetAttempts();
1741
- setAuthType("EmailOTP");
1742
- setOtpVisible(true);
1743
- if (!sendEmailOTP) return [3 /*break*/, 2];
1744
- setLoading(true);
1745
- return [4 /*yield*/, sendEmailOTP()];
1746
- case 1:
1747
- success = _a.sent();
1748
- setLoading(false);
1749
- if (success) {
1750
- toast.success(jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsx(ShieldCheck, { className: "w-4 h-4" }), jsx("span", { children: "OTP sent to your email address" })] }));
1751
- }
1752
- _a.label = 2;
1753
- case 2: return [2 /*return*/];
1754
- }
1755
- });
1756
- }); }, children: [jsx(Mail, { className: "w-5 h-5" }), jsxs("div", { className: "text-left", children: [jsx("div", { className: "font-medium", children: "Email OTP" }), jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), 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 () {
1622
+ content = (jsxs("div", { className: "space-y-4", children: [jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxs("div", { className: "flex flex-col gap-3", children: [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 () {
1757
1623
  setAuthType("AuthenticatorCode");
1758
1624
  setOtpVisible(true);
1759
1625
  }, children: [jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsx(Shield, {}); } }), jsxs("div", { className: "text-left", children: [jsx("div", { className: "font-medium", children: "Authenticator App" }), jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (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",
@@ -1762,7 +1628,9 @@ var MFAOptions = function (_a) {
1762
1628
  // setAuthType("AuthenticatorCode");
1763
1629
  // setOtpVisible(true);
1764
1630
  // }}
1765
- onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsx(KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxs("div", { className: "text-left", children: [jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
1631
+ onClick: function () {
1632
+ return authenticator.HandleFIDOLogin(MFAEndpoints.RetrieveAuthChallenge, MFAEndpoints.AuthChallengeVerify, authenticate);
1633
+ }, disabled: context.isLoading, children: [jsx(KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxs("div", { className: "text-left", children: [jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
1766
1634
  }
1767
1635
  else if (authType === "EmailOTP") {
1768
1636
  content = (jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -1825,6 +1693,7 @@ var ADLoginModal = function (_a) {
1825
1693
  username: credentials.username,
1826
1694
  password: credentials.password,
1827
1695
  MFACode: code,
1696
+ appCode: "",
1828
1697
  })];
1829
1698
  case 2:
1830
1699
  _a.sent();
@@ -1850,17 +1719,17 @@ var ADLoginModal = function (_a) {
1850
1719
  form.reset();
1851
1720
  setMfaCode("");
1852
1721
  };
1853
- return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-2", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsx(Form, __assign({}, form, { children: jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1722
+ return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-4", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "credentials" ? (jsx(Form, __assign({}, form, { children: jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1854
1723
  var field = _a.field;
1855
1724
  return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Username" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsx(FormMessage, {})] }));
1856
1725
  } }), jsx(FormField, { control: form.control, name: "password", render: function (_a) {
1857
1726
  var field = _a.field;
1858
1727
  return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Password" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsx(FormMessage, {})] }));
1859
- } }), jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1728
+ } }), jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1860
1729
  };
1861
1730
 
1862
1731
  var DefaultLoginPage = function (_a) {
1863
- var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
1732
+ var _b = _a.username, username = _b === void 0 ? "" : _b, usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
1864
1733
  var cardVariants = {
1865
1734
  hidden: { opacity: 0, scale: 0.8, y: 50 },
1866
1735
  visible: {
@@ -1873,22 +1742,31 @@ var DefaultLoginPage = function (_a) {
1873
1742
  };
1874
1743
  var context = useCAMSContext();
1875
1744
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1876
- var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
1745
+ var _c = useState(false), showADModal = _c[0], setShowADModal = _c[1];
1877
1746
  var register = useWebAuthn().register;
1878
- var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1747
+ var authentication = new CAMSMFAAuthenticator();
1748
+ var _d = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
1879
1749
  return __generator$1(this, function (_a) {
1880
1750
  console.log(data);
1881
- if (state && data) {
1751
+ if (state && data && data.isValid) {
1882
1752
  context.isAuthenticated = true;
1883
1753
  context.requiresMFA = false;
1884
1754
  context.setUserProfile({
1885
- type: "AUTH_SUCCESS",
1886
- userProfile: __assign({}, data),
1755
+ state: "AUTH_SUCCESS",
1756
+ role: data.data.role,
1757
+ profile: {
1758
+ id: data.data.id,
1759
+ name: data.data.name,
1760
+ email: data.data.email,
1761
+ isMFAEnabled: data.data.isMFAEnabled,
1762
+ message: data.message,
1763
+ tokens: data.tokens,
1764
+ },
1887
1765
  });
1888
1766
  }
1889
1767
  return [2 /*return*/];
1890
1768
  });
1891
- }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
1769
+ }); }), handleSubmitCredentials = _d.handleSubmitCredentials, isCredAuthLoading = _d.loading, setIsCredAuthLoading = _d.setLoading;
1892
1770
  var handleMSALLogin = function () {
1893
1771
  if (typeof window !== "undefined" && !window.crypto) {
1894
1772
  toast.error("Crypto API not available. Please use a modern browser.");
@@ -1902,53 +1780,21 @@ var DefaultLoginPage = function (_a) {
1902
1780
  console.warn("Regular CAMS login requires configuration");
1903
1781
  }
1904
1782
  };
1905
- var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
1906
- var options, attestationResponse, error_1;
1907
- return __generator$1(this, function (_a) {
1908
- switch (_a.label) {
1909
- case 0:
1910
- _a.trys.push([0, 4, , 5]);
1911
- // 1. Fetch challenge from your server
1912
- console.log("Requesting registration challenge from server...");
1913
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
1914
- case 1:
1915
- options = (_a.sent()).data;
1916
- console.log("Received challenge:", options);
1917
- // 2. Call the SDK to trigger the browser's passkey creation UI
1918
- console.log("Calling SDK register function...");
1919
- return [4 /*yield*/, register(options)];
1920
- case 2:
1921
- attestationResponse = _a.sent();
1922
- console.log("Passkey created on client:", attestationResponse);
1923
- // 3. Send the response back to the server for verification
1924
- console.log("Sending attestation to server for verification...");
1925
- return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
1926
- case 3:
1927
- _a.sent();
1928
- toast.success("✅ Registration successful! Passkey created.");
1929
- return [3 /*break*/, 5];
1930
- case 4:
1931
- error_1 = _a.sent();
1932
- console.error("Registration failed:", error_1);
1933
- toast.error("❌ Could not create passkey.");
1934
- return [3 /*break*/, 5];
1935
- case 5: return [2 /*return*/];
1936
- }
1937
- });
1938
- }); };
1939
- 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: 265, height: 265 }) }), 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
1783
+ 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
1940
1784
  // variant="outline"
1941
1785
  , {
1942
1786
  // variant="outline"
1943
1787
  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: [jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (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: [jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsx("span", { children: isLoading
1944
1788
  ? "Logging in..."
1945
- : "Sign in with ActiveDirectory" })] })), usePassKey && (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: [jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsx("span", { children: "Create a Passkey" })] }))] }), jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
1789
+ : "Sign in with ActiveDirectory" })] })), usePassKey && (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 () {
1790
+ return authentication.HandleRegister(MFAEndpoints.RegisterNewChallenge, MFAEndpoints.RegisterVerify +
1791
+ "?username=".concat(username), register, PassKeysRegisterProps);
1792
+ }, disabled: isLoading, children: [jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsx("span", { children: "Create a Passkey" })] }))] }), jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
1946
1793
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
1947
1794
  return __generator$1(this, function (_c) {
1948
1795
  // Implement your AD login logic here
1949
- console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
1950
- // Example: await adLoginService(username, password, mfaCode);
1951
- handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
1796
+ console.log("AD Login:", { username: username, MFACode: MFACode });
1797
+ handleSubmitCredentials(CredentialsAuthEndpoint, { username: username, password: password, MFACode: MFACode, appCode: context.appCode });
1952
1798
  return [2 /*return*/];
1953
1799
  });
1954
1800
  }); } })] }));
@@ -1967,7 +1813,7 @@ var MFAEndpointsSchema = z$1.object({
1967
1813
  AuthChallengeVerify: z$1.url("MFA AuthChallengeVerify must be a valid URL"),
1968
1814
  });
1969
1815
  var MFAGate = function (_a) {
1970
- var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsx("div", { className: 'h-screen flex items-center justify-center', children: jsx(LoadingSpinner, {}) }) : _b,
1816
+ var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? (jsx("div", { className: "h-screen flex items-center justify-center", children: jsx(LoadingSpinner, {}) })) : _b,
1971
1817
  // loginComponent: LoginComponent = DefaultLoginPage,
1972
1818
  _c = _a.usePassKey,
1973
1819
  // loginComponent: LoginComponent = DefaultLoginPage,
@@ -1995,7 +1841,7 @@ var MFAGate = function (_a) {
1995
1841
  }
1996
1842
  }
1997
1843
  else if (!success) {
1998
- Logger.error("MFA authentication failed");
1844
+ Logger.error("MFA authentication failed", { context: context || null });
1999
1845
  }
2000
1846
  }, [context, onAuthSuccess]);
2001
1847
  var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
@@ -2016,6 +1862,14 @@ var MFAGate = function (_a) {
2016
1862
  }
2017
1863
  });
2018
1864
  }); }, [context, onAuthError]);
1865
+ useEffect(function () {
1866
+ if (requiresMFA === false &&
1867
+ "accessToken" in context &&
1868
+ context.accessToken &&
1869
+ "setRequiresMFA" in context) {
1870
+ context.setRequiresMFA(false);
1871
+ }
1872
+ }, [requiresMFA, context]);
2019
1873
  if (useADLogin && !CredentialsAuthEndpoint)
2020
1874
  return jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2021
1875
  if (!validatedMFAEndpoints)
@@ -2027,11 +1881,6 @@ var MFAGate = function (_a) {
2027
1881
  if (!context.isAuthenticated) {
2028
1882
  var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : ("requiresMFA" in context ? context.requiresMFA : false);
2029
1883
  var accessToken = "accessToken" in context ? context.accessToken : "";
2030
- // If requiresMFA is explicitly set to false, bypass MFA and mark as authenticated
2031
- if (requiresMFA === false && accessToken && "setRequiresMFA" in context) {
2032
- context.setRequiresMFA(false);
2033
- return jsx(Fragment, { children: children });
2034
- }
2035
1884
  if (shouldRequireMFA && accessToken) {
2036
1885
  return (jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2037
1886
  }