@nibssplc/cams-sdk-react 0.0.1-beta.99 → 1.0.0-rc.10

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
@@ -18,6 +18,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
18
18
  import { toast } from 'sonner';
19
19
  import { motion } from 'framer-motion';
20
20
  import axios from 'axios';
21
+ import https from 'https';
21
22
 
22
23
  /******************************************************************************
23
24
  Copyright (c) Microsoft Corporation.
@@ -311,7 +312,6 @@ function useCAMSMSALAuth(options) {
311
312
  setMfaAuthenticator(authenticator);
312
313
  setRequiresMFA(true);
313
314
  }
314
- Logger.debug("App Code", { ">>>": options.appCode });
315
315
  }
316
316
  else {
317
317
  localStorage.removeItem(storageKey);
@@ -561,21 +561,13 @@ function register(options) {
561
561
  case 0:
562
562
  _k.trys.push([0, 2, , 3]);
563
563
  createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
564
- console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
565
564
  return [4 /*yield*/, navigator.credentials.create({
566
- publicKey: __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
565
+ publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
567
566
  type: "public-key",
568
567
  alg: param.alg,
569
- }); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
570
- // authenticatorAttachment:
571
- // (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
572
- // "platform") as AuthenticatorAttachment,
573
- // requireResidentKey:
574
- // (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
575
- // "false") === "true",
576
- residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
568
+ }); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
577
569
  "discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
578
- "preferred") }) }),
570
+ "discouraged") }) }),
579
571
  })];
580
572
  case 1:
581
573
  credential = _k.sent();
@@ -596,12 +588,16 @@ function register(options) {
596
588
  }];
597
589
  case 2:
598
590
  err_1 = _k.sent();
591
+ console.error("Error during registration:", err_1);
599
592
  if (err_1.name === "NotAllowedError") {
600
- throw new Error("Registration cancelled by user.");
593
+ throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
601
594
  }
602
595
  if (err_1.name === "InvalidStateError") {
603
596
  throw new Error("Passkey already registered for this user.");
604
597
  }
598
+ if (err_1.name === "NotSupportedError") {
599
+ throw new Error("Passkeys not supported on this device.");
600
+ }
605
601
  throw err_1;
606
602
  case 3: return [2 /*return*/];
607
603
  }
@@ -1706,7 +1702,7 @@ styleInject(css_248z);
1706
1702
 
1707
1703
  var LoadingSpinner = function (_a) {
1708
1704
  var loadingText = _a.loadingText;
1709
- return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
1705
+ return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col justify-center items-center h-full w-full py-10", children: [jsxRuntimeExports.jsx("script", { type: "module", defer: true, src: "https://cdn.jsdelivr.net/npm/ldrs/dist/auto/waveform.js" }), jsxRuntimeExports.jsx(r, { size: "35", stroke: "3.5", speed: "1", color: "green" }), loadingText && (jsxRuntimeExports.jsx("p", { className: "text-center font-semibold mt-3", children: "Loading..." }))] }));
1710
1706
  };
1711
1707
 
1712
1708
  var AuthSuccessAnimation = function (_a) {
@@ -1723,7 +1719,7 @@ var GenerateDeviceId = function () {
1723
1719
  var userAgent = window.navigator.userAgent;
1724
1720
  var deviceId = "";
1725
1721
  // Parse browser, version, OS, and device type
1726
- var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/ig));
1722
+ var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
1727
1723
  var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
1728
1724
  var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
1729
1725
  // Browser info
@@ -1753,6 +1749,31 @@ var GenerateDeviceId = function () {
1753
1749
  deviceId += "_".concat(hash);
1754
1750
  return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
1755
1751
  };
1752
+ var APIHeaders = {
1753
+ "X-DEVICE-ID": GenerateDeviceId(),
1754
+ "X-API-VERSION": "1.0",
1755
+ };
1756
+
1757
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1758
+ var axiosInstance = axios.create({
1759
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1760
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1761
+ });
1762
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1763
+ axiosInstance.interceptors.request.use(function (config) {
1764
+ var _a;
1765
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1766
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1767
+ return config; // Returns the modified request configuration.
1768
+ }, function (axiosError) {
1769
+ var _a, _b;
1770
+ // Handles request errors.
1771
+ return {
1772
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1773
+ message: axiosError.message, // Extracts the error message.
1774
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1775
+ };
1776
+ });
1756
1777
 
1757
1778
  var MAX_ATTEMPTS = 3;
1758
1779
  var useOTPHandler = function (_a) {
@@ -1779,18 +1800,13 @@ var useOTPHandler = function (_a) {
1779
1800
  setAttemptCount(currentAttempt);
1780
1801
  if (authenticationType === null)
1781
1802
  return [2 /*return*/, false];
1782
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1803
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1783
1804
  provider: provider,
1784
1805
  accessToken: accessToken,
1785
1806
  idToken: idToken,
1786
1807
  authenticationType: authenticationType,
1787
1808
  MFACode: authenticationValue,
1788
1809
  appCode: appCode,
1789
- }, {
1790
- headers: {
1791
- "X-Device-ID": GenerateDeviceId(),
1792
- },
1793
- timeout: 605000,
1794
1810
  })];
1795
1811
  case 2:
1796
1812
  response = (_a.sent()).data;
@@ -1852,6 +1868,75 @@ var useOTPHandler = function (_a) {
1852
1868
  remainingAttempts: MAX_ATTEMPTS - attemptCount,
1853
1869
  };
1854
1870
  };
1871
+ var useCredentialsHandler = function (onAuthComplete) {
1872
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
1873
+ var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1874
+ var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1875
+ var handleSubmitCredentials = useMemo(function () {
1876
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
1877
+ var currentAttempt, response, error_2, currentAttempt;
1878
+ return __generator(this, function (_a) {
1879
+ switch (_a.label) {
1880
+ case 0:
1881
+ _a.trys.push([0, 2, 3, 4]);
1882
+ setLoading(true);
1883
+ currentAttempt = attemptCount + 1;
1884
+ setAttemptCount(currentAttempt);
1885
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1886
+ username: credentials.username,
1887
+ password: credentials.password,
1888
+ MFACode: credentials.MFACode,
1889
+ appCode: appCode,
1890
+ })];
1891
+ case 1:
1892
+ response = (_a.sent()).data;
1893
+ if (response) {
1894
+ onAuthComplete(true, response);
1895
+ return [2 /*return*/, true];
1896
+ }
1897
+ else {
1898
+ if (currentAttempt >= MAX_ATTEMPTS) {
1899
+ setIsMaxAttemptsReached(true);
1900
+ onAuthComplete(false, {
1901
+ message: "Maximum attempts reached",
1902
+ });
1903
+ }
1904
+ else {
1905
+ onAuthComplete(false, response.response.data);
1906
+ }
1907
+ return [2 /*return*/, false];
1908
+ }
1909
+ case 2:
1910
+ error_2 = _a.sent();
1911
+ console.error(error_2);
1912
+ currentAttempt = attemptCount + 1;
1913
+ if (currentAttempt >= MAX_ATTEMPTS) {
1914
+ setIsMaxAttemptsReached(true);
1915
+ onAuthComplete(false, error_2.response.data);
1916
+ }
1917
+ else {
1918
+ onAuthComplete(false, error_2.response.data);
1919
+ }
1920
+ onAuthComplete(false, error_2.response.data);
1921
+ return [2 /*return*/, false];
1922
+ case 3:
1923
+ setLoading(false);
1924
+ return [7 /*endfinally*/];
1925
+ case 4: return [2 /*return*/];
1926
+ }
1927
+ });
1928
+ }); };
1929
+ }, []);
1930
+ return {
1931
+ handleSubmitCredentials: handleSubmitCredentials,
1932
+ loading: loading,
1933
+ setLoading: setLoading,
1934
+ attemptCount: attemptCount,
1935
+ isMaxAttemptsReached: isMaxAttemptsReached,
1936
+ // resetAttempts,
1937
+ remainingAttempts: MAX_ATTEMPTS - attemptCount,
1938
+ };
1939
+ };
1855
1940
 
1856
1941
  var MFAOptions = function (_a) {
1857
1942
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
@@ -1870,46 +1955,31 @@ var MFAOptions = function (_a) {
1870
1955
  var authenticate = useWebAuthn().authenticate;
1871
1956
  var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
1872
1957
  var options, assertionResponse, error_1;
1873
- var _a, _b, _c, _d, _e, _f;
1874
- return __generator(this, function (_g) {
1875
- switch (_g.label) {
1958
+ return __generator(this, function (_a) {
1959
+ switch (_a.label) {
1876
1960
  case 0:
1877
- _g.trys.push([0, 4, , 5]);
1961
+ _a.trys.push([0, 4, , 5]);
1878
1962
  // 1. Fetch authentication challenge from your server
1879
1963
  console.log("Requesting authentication challenge from server...");
1880
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1881
- headers: {
1882
- "X-DEVICE-ID": GenerateDeviceId(),
1883
- "X-API-VERSION": "1.0",
1884
- },
1885
- })];
1964
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1886
1965
  case 1:
1887
- options = (_g.sent()).data;
1966
+ options = (_a.sent()).data;
1888
1967
  console.log("Received challenge:", options);
1889
1968
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1890
1969
  console.log("Calling SDK authenticate function...");
1891
- return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1892
- type: "public-key",
1893
- alg: param.alg
1894
- }); }), attestation: ((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none", authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), { residentKey: ((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || "discouraged", userVerification: ((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) || "preferred" }) }))];
1970
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
1895
1971
  case 2:
1896
- assertionResponse = _g.sent();
1972
+ assertionResponse = _a.sent();
1897
1973
  console.log("Authentication assertion received from client:", assertionResponse);
1898
1974
  // 3. Send the assertion back to the server for verification
1899
1975
  console.log("Sending assertion to server for verification...");
1900
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1901
- headers: {
1902
- "X-DEVICE-ID": GenerateDeviceId(),
1903
- "X-API-VERSION": "1.0",
1904
- },
1905
- withCredentials: true, // credentials: 'include'
1906
- })];
1976
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1907
1977
  case 3:
1908
- _g.sent();
1978
+ _a.sent();
1909
1979
  toast.success("🔑 Sign-in successful!");
1910
1980
  return [3 /*break*/, 5];
1911
1981
  case 4:
1912
- error_1 = _g.sent();
1982
+ error_1 = _a.sent();
1913
1983
  console.error("Authentication failed:", error_1);
1914
1984
  toast.error("❌ Could not sign in.");
1915
1985
  return [3 /*break*/, 5];
@@ -1970,7 +2040,7 @@ var MFAOptions = function (_a) {
1970
2040
  return __generator(this, function (_a) {
1971
2041
  switch (_a.label) {
1972
2042
  case 0:
1973
- resetAttempts();
2043
+ // resetAttempts();
1974
2044
  setAuthType("EmailOTP");
1975
2045
  setOtpVisible(true);
1976
2046
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -1987,7 +2057,6 @@ var MFAOptions = function (_a) {
1987
2057
  }
1988
2058
  });
1989
2059
  }); }, children: [jsxRuntimeExports.jsx(Mail, { className: "w-5 h-5" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Email OTP" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Send code to your email" })] })] }), jsxRuntimeExports.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 () {
1990
- resetAttempts();
1991
2060
  setAuthType("AuthenticatorCode");
1992
2061
  setOtpVisible(true);
1993
2062
  }, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(Shield, {}); } }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Authenticator App" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Use Authenticator App" })] })] }), usePassKey && (jsxRuntimeExports.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",
@@ -1996,7 +2065,7 @@ var MFAOptions = function (_a) {
1996
2065
  // setAuthType("AuthenticatorCode");
1997
2066
  // setOtpVisible(true);
1998
2067
  // }}
1999
- onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(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", children: jsxRuntimeExports.jsx("span", { children: "Sign In " }) }), jsxRuntimeExports.jsx(KeyIcon, { className: "w-16 h-16 text-[#506f4a]" }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
2068
+ onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 48 }), jsxRuntimeExports.jsxs("div", { className: "text-left", children: [jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Continue with Passkey" }), jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: "Passkey" })] })] }))] })] }));
2000
2069
  }
2001
2070
  else if (authType === "EmailOTP") {
2002
2071
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2028,14 +2097,13 @@ var credentialsSchema = z.object({
2028
2097
  password: z.string().min(1, "Password is required"),
2029
2098
  });
2030
2099
  var ADLoginModal = function (_a) {
2031
- var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2100
+ var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2032
2101
  var _b = useState("credentials"), step = _b[0], setStep = _b[1];
2033
2102
  var _c = useState({
2034
2103
  username: "",
2035
2104
  password: "",
2036
2105
  }), credentials = _c[0], setCredentials = _c[1];
2037
2106
  var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
2038
- var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
2039
2107
  var form = useForm({
2040
2108
  resolver: a$1(credentialsSchema),
2041
2109
  defaultValues: { username: "", password: "" },
@@ -2085,21 +2153,45 @@ var ADLoginModal = function (_a) {
2085
2153
  form.reset();
2086
2154
  setMfaCode("");
2087
2155
  };
2088
- return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[85%]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
2156
+ return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
2089
2157
  var field = _a.field;
2090
- return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
2158
+ return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
2091
2159
  } }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
2092
2160
  var field = _a.field;
2093
- return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
2161
+ return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Password" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
2094
2162
  } }), jsxRuntimeExports.jsx(Button, { type: "submit", className: "w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntimeExports.jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
2095
2163
  };
2096
2164
 
2097
2165
  var DefaultLoginPage = function (_a) {
2098
- var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2166
+ var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2167
+ var cardVariants = {
2168
+ hidden: { opacity: 0, scale: 0.8, y: 50 },
2169
+ visible: {
2170
+ opacity: 1,
2171
+ scale: 1,
2172
+ y: 0,
2173
+ transition: { type: "spring", duration: 0.6 },
2174
+ },
2175
+ exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
2176
+ };
2099
2177
  var context = useCAMSContext();
2100
2178
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2101
2179
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
2102
2180
  var register = useWebAuthn().register;
2181
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2182
+ return __generator(this, function (_a) {
2183
+ console.log(data);
2184
+ if (state && data) {
2185
+ context.isAuthenticated = true;
2186
+ context.requiresMFA = false;
2187
+ context.setUserProfile({
2188
+ type: "AUTH_SUCCESS",
2189
+ userProfile: __assign({}, data),
2190
+ });
2191
+ }
2192
+ return [2 /*return*/];
2193
+ });
2194
+ }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2103
2195
  var handleMSALLogin = function () {
2104
2196
  if (authMode === "MSAL") {
2105
2197
  login();
@@ -2109,16 +2201,6 @@ var DefaultLoginPage = function (_a) {
2109
2201
  console.warn("Regular CAMS login requires configuration");
2110
2202
  }
2111
2203
  };
2112
- var cardVariants = {
2113
- hidden: { opacity: 0, scale: 0.8, y: 50 },
2114
- visible: {
2115
- opacity: 1,
2116
- scale: 1,
2117
- y: 0,
2118
- transition: { type: "spring", duration: 0.6 },
2119
- },
2120
- exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
2121
- };
2122
2204
  var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2123
2205
  var options, attestationResponse, error_1;
2124
2206
  return __generator(this, function (_a) {
@@ -2127,12 +2209,7 @@ var DefaultLoginPage = function (_a) {
2127
2209
  _a.trys.push([0, 4, , 5]);
2128
2210
  // 1. Fetch challenge from your server
2129
2211
  console.log("Requesting registration challenge from server...");
2130
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2131
- headers: {
2132
- "X-DEVICE-ID": GenerateDeviceId(),
2133
- "X-API-VERSION": "1.0",
2134
- },
2135
- })];
2212
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2136
2213
  case 1:
2137
2214
  options = (_a.sent()).data;
2138
2215
  console.log("Received challenge:", options);
@@ -2144,13 +2221,7 @@ var DefaultLoginPage = function (_a) {
2144
2221
  console.log("Passkey created on client:", attestationResponse);
2145
2222
  // 3. Send the response back to the server for verification
2146
2223
  console.log("Sending attestation to server for verification...");
2147
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2148
- headers: {
2149
- "X-DEVICE-ID": GenerateDeviceId(),
2150
- "X-API-VERSION": "1.0",
2151
- },
2152
- withCredentials: true, // credentials: 'include'
2153
- })];
2224
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2154
2225
  case 3:
2155
2226
  _a.sent();
2156
2227
  toast.success("✅ Registration successful! Passkey created.");
@@ -2168,11 +2239,15 @@ var DefaultLoginPage = function (_a) {
2168
2239
  // variant="outline"
2169
2240
  , {
2170
2241
  // variant="outline"
2171
- 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: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), jsxRuntimeExports.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: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with ActiveDirectory" })] }), usePassKey && (jsxRuntimeExports.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: [jsxRuntimeExports.jsx(KeyIcon, { className: "w-12 h-12 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
2242
+ 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: [jsxRuntimeExports.jsx("img", { src: MicrosoftLogo, alt: "Microsoft Logo", width: 35, height: 35 }), jsxRuntimeExports.jsx("span", { className: "ml-2", children: isLoading ? "Logging in..." : "Sign in with Microsoft" })] }), useADLogin && (jsxRuntimeExports.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: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
2243
+ ? "Logging in..."
2244
+ : "Sign in with ActiveDirectory" })] })), usePassKey && (jsxRuntimeExports.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: [jsxRuntimeExports.jsx(KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: "Create a Passkey" })] }))] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, isLoading: isCredAuthLoading, setIsLoading: setIsCredAuthLoading, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
2172
2245
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2173
2246
  return __generator(this, function (_c) {
2174
2247
  // Implement your AD login logic here
2175
2248
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2249
+ // Example: await adLoginService(username, password, mfaCode);
2250
+ handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
2176
2251
  return [2 /*return*/];
2177
2252
  });
2178
2253
  }); } })] }));
@@ -2195,7 +2270,7 @@ var MFAGate = function (_a) {
2195
2270
  // loginComponent: LoginComponent = DefaultLoginPage,
2196
2271
  _c = _a.usePassKey,
2197
2272
  // loginComponent: LoginComponent = DefaultLoginPage,
2198
- usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2273
+ usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2199
2274
  var context = useCAMSContext();
2200
2275
  var validatedMFAEndpoints = useMemo(function () {
2201
2276
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
@@ -2219,9 +2294,10 @@ var MFAGate = function (_a) {
2219
2294
  }
2220
2295
  });
2221
2296
  }); }, [context.logout]);
2222
- Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2297
+ if (useADLogin && !CredentialsAuthEndpoint)
2298
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2223
2299
  if (!validatedMFAEndpoints)
2224
- return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA configuration." });
2300
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
2225
2301
  if (context.authMode !== "MSAL")
2226
2302
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2227
2303
  if (context.isLoading)
@@ -2230,7 +2306,7 @@ var MFAGate = function (_a) {
2230
2306
  return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2231
2307
  }
2232
2308
  if (!context.isAuthenticated) {
2233
- return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
2309
+ return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
2234
2310
  }
2235
2311
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2236
2312
  };