@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.
@@ -1,7 +1,9 @@
1
1
  interface ADLoginModalProps {
2
2
  open: boolean;
3
+ isLoading: boolean;
4
+ setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
3
5
  onOpenChange: (open: boolean) => void;
4
6
  onLogin: (credentials: Credentials) => Promise<void>;
5
7
  }
6
- export declare const ADLoginModal: ({ open, onOpenChange, onLogin, }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const ADLoginModal: ({ open, isLoading, setIsLoading, onOpenChange, onLogin, }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
7
9
  export {};
@@ -1,8 +1,10 @@
1
1
  import { MFAEndpoints } from "./MFAGate";
2
2
  interface LoginPageProps {
3
3
  usePassKey?: boolean;
4
+ CredentialsAuthEndpoint?: string;
5
+ useADLogin?: boolean;
4
6
  MFAEndpoints: MFAEndpoints;
5
7
  PassKeysRegisterProps?: Record<string, unknown>;
6
8
  }
7
- declare const DefaultLoginPage: ({ usePassKey, MFAEndpoints, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
9
+ declare const DefaultLoginPage: ({ usePassKey, useADLogin, MFAEndpoints, CredentialsAuthEndpoint, PassKeysRegisterProps, }: LoginPageProps) => import("react/jsx-runtime").JSX.Element;
8
10
  export default DefaultLoginPage;
@@ -11,8 +11,10 @@ interface MFAGateProps {
11
11
  children: React.ReactNode;
12
12
  fallback?: React.ReactNode;
13
13
  usePassKey?: boolean;
14
+ useADLogin?: boolean;
15
+ CredentialsAuthEndpoint?: string;
14
16
  PassKeysRegisterProps?: Record<string, unknown>;
15
17
  MFAEndpoints?: MFAEndpoints;
16
18
  }
17
- declare const MFAGate: ({ children, fallback, usePassKey, PassKeysRegisterProps, MFAEndpoints, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
19
+ declare const MFAGate: ({ children, fallback, usePassKey, useADLogin, CredentialsAuthEndpoint, PassKeysRegisterProps, MFAEndpoints, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
18
20
  export default MFAGate;
@@ -15,13 +15,8 @@ export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode,
15
15
  resetAttempts: () => void;
16
16
  remainingAttempts: number;
17
17
  };
18
- export declare const useCredentialsHandler: (credentials: Credentials, appCode: string, CredAuthEndpoint: string, onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void) => {
19
- handleSubmitCredentials: ({ username, password, MFACode, appCode, }: {
20
- username: string;
21
- password: string;
22
- MFACode: string;
23
- appCode: string;
24
- }) => Promise<boolean>;
18
+ export declare const useCredentialsHandler: (onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void) => {
19
+ handleSubmitCredentials: (CredAuthEndpoint: string, credentials: Credentials, appCode: string) => Promise<boolean>;
25
20
  loading: boolean;
26
21
  setLoading: import("react").Dispatch<import("react").SetStateAction<boolean>>;
27
22
  attemptCount: number;
package/dist/index.cjs.js CHANGED
@@ -18,6 +18,7 @@ var DialogPrimitive = require('@radix-ui/react-dialog');
18
18
  var sonner = require('sonner');
19
19
  var framerMotion = require('framer-motion');
20
20
  var axios = require('axios');
21
+ var https = require('https');
21
22
 
22
23
  function _interopNamespaceDefault(e) {
23
24
  var n = Object.create(null);
@@ -332,7 +333,6 @@ function useCAMSMSALAuth(options) {
332
333
  setMfaAuthenticator(authenticator);
333
334
  setRequiresMFA(true);
334
335
  }
335
- camsSdk.Logger.debug("App Code", { ">>>": options.appCode });
336
336
  }
337
337
  else {
338
338
  localStorage.removeItem(storageKey);
@@ -582,21 +582,13 @@ function register(options) {
582
582
  case 0:
583
583
  _k.trys.push([0, 2, , 3]);
584
584
  createOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), user: __assign(__assign({}, options.user), { id: base64urlToArrayBuffer(options.user.id) }) });
585
- console.log("Creating credential with options:", createOptions, "...\n\n\n", options);
586
585
  return [4 /*yield*/, navigator.credentials.create({
587
- publicKey: __assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
586
+ publicKey: __assign(__assign({}, createOptions), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
588
587
  type: "public-key",
589
588
  alg: param.alg,
590
- }); }), attestation: (((_b = options.attestation) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "none"), authenticatorSelection: __assign(__assign({}, options.authenticatorSelection), {
591
- // authenticatorAttachment:
592
- // (options.authenticatorSelection?.authenticatorAttachment?.toLowerCase() ||
593
- // "platform") as AuthenticatorAttachment,
594
- // requireResidentKey:
595
- // (options.authenticatorSelection?.requireResidentKey?.toLowerCase() ||
596
- // "false") === "true",
597
- residentKey: (((_d = (_c = options.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.residentKey) === null || _d === void 0 ? void 0 : _d.toLowerCase()) ||
589
+ }); }), 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()) ||
598
590
  "discouraged"), userVerification: (((_f = (_e = options.authenticatorSelection) === null || _e === void 0 ? void 0 : _e.userVerification) === null || _f === void 0 ? void 0 : _f.toLowerCase()) ||
599
- "preferred") }) }),
591
+ "discouraged") }) }),
600
592
  })];
601
593
  case 1:
602
594
  credential = _k.sent();
@@ -617,12 +609,16 @@ function register(options) {
617
609
  }];
618
610
  case 2:
619
611
  err_1 = _k.sent();
612
+ console.error("Error during registration:", err_1);
620
613
  if (err_1.name === "NotAllowedError") {
621
- throw new Error("Registration cancelled by user.");
614
+ throw new Error("Face ID/Touch ID cancelled or failed. Please try again.");
622
615
  }
623
616
  if (err_1.name === "InvalidStateError") {
624
617
  throw new Error("Passkey already registered for this user.");
625
618
  }
619
+ if (err_1.name === "NotSupportedError") {
620
+ throw new Error("Passkeys not supported on this device.");
621
+ }
626
622
  throw err_1;
627
623
  case 3: return [2 /*return*/];
628
624
  }
@@ -1727,7 +1723,7 @@ styleInject(css_248z);
1727
1723
 
1728
1724
  var LoadingSpinner = function (_a) {
1729
1725
  var loadingText = _a.loadingText;
1730
- 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..." }))] }));
1726
+ 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..." }))] }));
1731
1727
  };
1732
1728
 
1733
1729
  var AuthSuccessAnimation = function (_a) {
@@ -1744,7 +1740,7 @@ var GenerateDeviceId = function () {
1744
1740
  var userAgent = window.navigator.userAgent;
1745
1741
  var deviceId = "";
1746
1742
  // Parse browser, version, OS, and device type
1747
- var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/ig));
1743
+ var browserMatch = Array.from(userAgent.matchAll(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/gi));
1748
1744
  var osMatch = Array.from(userAgent.matchAll(/\(([^)]+)\)/g));
1749
1745
  var isMobile = /Mobile|Android|iPhone|iPad/i.test(userAgent);
1750
1746
  // Browser info
@@ -1774,6 +1770,31 @@ var GenerateDeviceId = function () {
1774
1770
  deviceId += "_".concat(hash);
1775
1771
  return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
1776
1772
  };
1773
+ var APIHeaders = {
1774
+ "X-DEVICE-ID": GenerateDeviceId(),
1775
+ "X-API-VERSION": "1.0",
1776
+ };
1777
+
1778
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1779
+ var axiosInstance = axios.create({
1780
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1781
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1782
+ });
1783
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1784
+ axiosInstance.interceptors.request.use(function (config) {
1785
+ var _a;
1786
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1787
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1788
+ return config; // Returns the modified request configuration.
1789
+ }, function (axiosError) {
1790
+ var _a, _b;
1791
+ // Handles request errors.
1792
+ return {
1793
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1794
+ message: axiosError.message, // Extracts the error message.
1795
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1796
+ };
1797
+ });
1777
1798
 
1778
1799
  var MAX_ATTEMPTS = 3;
1779
1800
  var useOTPHandler = function (_a) {
@@ -1800,18 +1821,13 @@ var useOTPHandler = function (_a) {
1800
1821
  setAttemptCount(currentAttempt);
1801
1822
  if (authenticationType === null)
1802
1823
  return [2 /*return*/, false];
1803
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1824
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1804
1825
  provider: provider,
1805
1826
  accessToken: accessToken,
1806
1827
  idToken: idToken,
1807
1828
  authenticationType: authenticationType,
1808
1829
  MFACode: authenticationValue,
1809
1830
  appCode: appCode,
1810
- }, {
1811
- headers: {
1812
- "X-Device-ID": GenerateDeviceId(),
1813
- },
1814
- timeout: 605000,
1815
1831
  })];
1816
1832
  case 2:
1817
1833
  response = (_a.sent()).data;
@@ -1873,6 +1889,75 @@ var useOTPHandler = function (_a) {
1873
1889
  remainingAttempts: MAX_ATTEMPTS - attemptCount,
1874
1890
  };
1875
1891
  };
1892
+ var useCredentialsHandler = function (onAuthComplete) {
1893
+ var _a = React.useState(false), loading = _a[0], setLoading = _a[1];
1894
+ var _b = React.useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1895
+ var _c = React.useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1896
+ var handleSubmitCredentials = React.useMemo(function () {
1897
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
1898
+ var currentAttempt, response, error_2, currentAttempt;
1899
+ return __generator(this, function (_a) {
1900
+ switch (_a.label) {
1901
+ case 0:
1902
+ _a.trys.push([0, 2, 3, 4]);
1903
+ setLoading(true);
1904
+ currentAttempt = attemptCount + 1;
1905
+ setAttemptCount(currentAttempt);
1906
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1907
+ username: credentials.username,
1908
+ password: credentials.password,
1909
+ MFACode: credentials.MFACode,
1910
+ appCode: appCode,
1911
+ })];
1912
+ case 1:
1913
+ response = (_a.sent()).data;
1914
+ if (response) {
1915
+ onAuthComplete(true, response);
1916
+ return [2 /*return*/, true];
1917
+ }
1918
+ else {
1919
+ if (currentAttempt >= MAX_ATTEMPTS) {
1920
+ setIsMaxAttemptsReached(true);
1921
+ onAuthComplete(false, {
1922
+ message: "Maximum attempts reached",
1923
+ });
1924
+ }
1925
+ else {
1926
+ onAuthComplete(false, response.response.data);
1927
+ }
1928
+ return [2 /*return*/, false];
1929
+ }
1930
+ case 2:
1931
+ error_2 = _a.sent();
1932
+ console.error(error_2);
1933
+ currentAttempt = attemptCount + 1;
1934
+ if (currentAttempt >= MAX_ATTEMPTS) {
1935
+ setIsMaxAttemptsReached(true);
1936
+ onAuthComplete(false, error_2.response.data);
1937
+ }
1938
+ else {
1939
+ onAuthComplete(false, error_2.response.data);
1940
+ }
1941
+ onAuthComplete(false, error_2.response.data);
1942
+ return [2 /*return*/, false];
1943
+ case 3:
1944
+ setLoading(false);
1945
+ return [7 /*endfinally*/];
1946
+ case 4: return [2 /*return*/];
1947
+ }
1948
+ });
1949
+ }); };
1950
+ }, []);
1951
+ return {
1952
+ handleSubmitCredentials: handleSubmitCredentials,
1953
+ loading: loading,
1954
+ setLoading: setLoading,
1955
+ attemptCount: attemptCount,
1956
+ isMaxAttemptsReached: isMaxAttemptsReached,
1957
+ // resetAttempts,
1958
+ remainingAttempts: MAX_ATTEMPTS - attemptCount,
1959
+ };
1960
+ };
1876
1961
 
1877
1962
  var MFAOptions = function (_a) {
1878
1963
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
@@ -1891,46 +1976,31 @@ var MFAOptions = function (_a) {
1891
1976
  var authenticate = useWebAuthn().authenticate;
1892
1977
  var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
1893
1978
  var options, assertionResponse, error_1;
1894
- var _a, _b, _c, _d, _e, _f;
1895
- return __generator(this, function (_g) {
1896
- switch (_g.label) {
1979
+ return __generator(this, function (_a) {
1980
+ switch (_a.label) {
1897
1981
  case 0:
1898
- _g.trys.push([0, 4, , 5]);
1982
+ _a.trys.push([0, 4, , 5]);
1899
1983
  // 1. Fetch authentication challenge from your server
1900
1984
  console.log("Requesting authentication challenge from server...");
1901
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1902
- headers: {
1903
- "X-DEVICE-ID": GenerateDeviceId(),
1904
- "X-API-VERSION": "1.0",
1905
- },
1906
- })];
1985
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1907
1986
  case 1:
1908
- options = (_g.sent()).data;
1987
+ options = (_a.sent()).data;
1909
1988
  console.log("Received challenge:", options);
1910
1989
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1911
1990
  console.log("Calling SDK authenticate function...");
1912
- return [4 /*yield*/, authenticate(__assign(__assign({}, options), { pubKeyCredParams: (_a = options.pubKeyCredParams) === null || _a === void 0 ? void 0 : _a.map(function (param) { return ({
1913
- type: "public-key",
1914
- alg: param.alg
1915
- }); }), 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" }) }))];
1991
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
1916
1992
  case 2:
1917
- assertionResponse = _g.sent();
1993
+ assertionResponse = _a.sent();
1918
1994
  console.log("Authentication assertion received from client:", assertionResponse);
1919
1995
  // 3. Send the assertion back to the server for verification
1920
1996
  console.log("Sending assertion to server for verification...");
1921
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1922
- headers: {
1923
- "X-DEVICE-ID": GenerateDeviceId(),
1924
- "X-API-VERSION": "1.0",
1925
- },
1926
- withCredentials: true, // credentials: 'include'
1927
- })];
1997
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1928
1998
  case 3:
1929
- _g.sent();
1999
+ _a.sent();
1930
2000
  sonner.toast.success("🔑 Sign-in successful!");
1931
2001
  return [3 /*break*/, 5];
1932
2002
  case 4:
1933
- error_1 = _g.sent();
2003
+ error_1 = _a.sent();
1934
2004
  console.error("Authentication failed:", error_1);
1935
2005
  sonner.toast.error("❌ Could not sign in.");
1936
2006
  return [3 /*break*/, 5];
@@ -1991,7 +2061,7 @@ var MFAOptions = function (_a) {
1991
2061
  return __generator(this, function (_a) {
1992
2062
  switch (_a.label) {
1993
2063
  case 0:
1994
- resetAttempts();
2064
+ // resetAttempts();
1995
2065
  setAuthType("EmailOTP");
1996
2066
  setOtpVisible(true);
1997
2067
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2008,7 +2078,6 @@ var MFAOptions = function (_a) {
2008
2078
  }
2009
2079
  });
2010
2080
  }); }, children: [jsxRuntimeExports.jsx(lucideReact.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 () {
2011
- resetAttempts();
2012
2081
  setAuthType("AuthenticatorCode");
2013
2082
  setOtpVisible(true);
2014
2083
  }, children: [jsxRuntimeExports.jsx("img", { src: MicrosoftAuthenticatorImg, alt: "Authenticator", className: "rounded-full", width: 24, height: 24, onError: function () { return jsxRuntimeExports.jsx(lucideReact.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",
@@ -2017,7 +2086,7 @@ var MFAOptions = function (_a) {
2017
2086
  // setAuthType("AuthenticatorCode");
2018
2087
  // setOtpVisible(true);
2019
2088
  // }}
2020
- 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(lucideReact.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" })] })] }))] })] }));
2089
+ onClick: handleFIDOLogin, disabled: context.isLoading, children: [jsxRuntimeExports.jsx(lucideReact.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" })] })] }))] })] }));
2021
2090
  }
2022
2091
  else if (authType === "EmailOTP") {
2023
2092
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2049,14 +2118,13 @@ var credentialsSchema = z.z.object({
2049
2118
  password: z.z.string().min(1, "Password is required"),
2050
2119
  });
2051
2120
  var ADLoginModal = function (_a) {
2052
- var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2121
+ var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2053
2122
  var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
2054
2123
  var _c = React.useState({
2055
2124
  username: "",
2056
2125
  password: "",
2057
2126
  }), credentials = _c[0], setCredentials = _c[1];
2058
2127
  var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
2059
- var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
2060
2128
  var form = reactHookForm.useForm({
2061
2129
  resolver: a$1(credentialsSchema),
2062
2130
  defaultValues: { username: "", password: "" },
@@ -2106,21 +2174,45 @@ var ADLoginModal = function (_a) {
2106
2174
  form.reset();
2107
2175
  setMfaCode("");
2108
2176
  };
2109
- 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(lucideReact.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) {
2177
+ 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(lucideReact.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) {
2110
2178
  var field = _a.field;
2111
- 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, {})] }));
2179
+ 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, {})] }));
2112
2180
  } }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
2113
2181
  var field = _a.field;
2114
- 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, {})] }));
2182
+ 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, {})] }));
2115
2183
  } }), 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(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntimeExports.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
2116
2184
  };
2117
2185
 
2118
2186
  var DefaultLoginPage = function (_a) {
2119
- var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2187
+ var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2188
+ var cardVariants = {
2189
+ hidden: { opacity: 0, scale: 0.8, y: 50 },
2190
+ visible: {
2191
+ opacity: 1,
2192
+ scale: 1,
2193
+ y: 0,
2194
+ transition: { type: "spring", duration: 0.6 },
2195
+ },
2196
+ exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
2197
+ };
2120
2198
  var context = useCAMSContext();
2121
2199
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2122
2200
  var _b = React.useState(false), showADModal = _b[0], setShowADModal = _b[1];
2123
2201
  var register = useWebAuthn().register;
2202
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2203
+ return __generator(this, function (_a) {
2204
+ console.log(data);
2205
+ if (state && data) {
2206
+ context.isAuthenticated = true;
2207
+ context.requiresMFA = false;
2208
+ context.setUserProfile({
2209
+ type: "AUTH_SUCCESS",
2210
+ userProfile: __assign({}, data),
2211
+ });
2212
+ }
2213
+ return [2 /*return*/];
2214
+ });
2215
+ }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2124
2216
  var handleMSALLogin = function () {
2125
2217
  if (authMode === "MSAL") {
2126
2218
  login();
@@ -2130,16 +2222,6 @@ var DefaultLoginPage = function (_a) {
2130
2222
  console.warn("Regular CAMS login requires configuration");
2131
2223
  }
2132
2224
  };
2133
- var cardVariants = {
2134
- hidden: { opacity: 0, scale: 0.8, y: 50 },
2135
- visible: {
2136
- opacity: 1,
2137
- scale: 1,
2138
- y: 0,
2139
- transition: { type: "spring", duration: 0.6 },
2140
- },
2141
- exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
2142
- };
2143
2225
  var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2144
2226
  var options, attestationResponse, error_1;
2145
2227
  return __generator(this, function (_a) {
@@ -2148,12 +2230,7 @@ var DefaultLoginPage = function (_a) {
2148
2230
  _a.trys.push([0, 4, , 5]);
2149
2231
  // 1. Fetch challenge from your server
2150
2232
  console.log("Requesting registration challenge from server...");
2151
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2152
- headers: {
2153
- "X-DEVICE-ID": GenerateDeviceId(),
2154
- "X-API-VERSION": "1.0",
2155
- },
2156
- })];
2233
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2157
2234
  case 1:
2158
2235
  options = (_a.sent()).data;
2159
2236
  console.log("Received challenge:", options);
@@ -2165,13 +2242,7 @@ var DefaultLoginPage = function (_a) {
2165
2242
  console.log("Passkey created on client:", attestationResponse);
2166
2243
  // 3. Send the response back to the server for verification
2167
2244
  console.log("Sending attestation to server for verification...");
2168
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2169
- headers: {
2170
- "X-DEVICE-ID": GenerateDeviceId(),
2171
- "X-API-VERSION": "1.0",
2172
- },
2173
- withCredentials: true, // credentials: 'include'
2174
- })];
2245
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2175
2246
  case 3:
2176
2247
  _a.sent();
2177
2248
  sonner.toast.success("✅ Registration successful! Passkey created.");
@@ -2189,11 +2260,15 @@ var DefaultLoginPage = function (_a) {
2189
2260
  // variant="outline"
2190
2261
  , {
2191
2262
  // variant="outline"
2192
- 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(lucideReact.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(lucideReact.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(lucideReact.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) {
2263
+ 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(lucideReact.KeyIcon, { className: "text-[#506f4a]", size: 64 }), jsxRuntimeExports.jsx("span", { children: isLoading
2264
+ ? "Logging in..."
2265
+ : "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(lucideReact.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(lucideReact.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) {
2193
2266
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2194
2267
  return __generator(this, function (_c) {
2195
2268
  // Implement your AD login logic here
2196
2269
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2270
+ // Example: await adLoginService(username, password, mfaCode);
2271
+ handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
2197
2272
  return [2 /*return*/];
2198
2273
  });
2199
2274
  }); } })] }));
@@ -2216,7 +2291,7 @@ var MFAGate = function (_a) {
2216
2291
  // loginComponent: LoginComponent = DefaultLoginPage,
2217
2292
  _c = _a.usePassKey,
2218
2293
  // loginComponent: LoginComponent = DefaultLoginPage,
2219
- usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2294
+ usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2220
2295
  var context = useCAMSContext();
2221
2296
  var validatedMFAEndpoints = React.useMemo(function () {
2222
2297
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
@@ -2240,9 +2315,10 @@ var MFAGate = function (_a) {
2240
2315
  }
2241
2316
  });
2242
2317
  }); }, [context.logout]);
2243
- camsSdk.Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2318
+ if (useADLogin && !CredentialsAuthEndpoint)
2319
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2244
2320
  if (!validatedMFAEndpoints)
2245
- return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA configuration." });
2321
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
2246
2322
  if (context.authMode !== "MSAL")
2247
2323
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2248
2324
  if (context.isLoading)
@@ -2251,7 +2327,7 @@ var MFAGate = function (_a) {
2251
2327
  return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2252
2328
  }
2253
2329
  if (!context.isAuthenticated) {
2254
- return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
2330
+ return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
2255
2331
  }
2256
2332
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2257
2333
  };