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

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
@@ -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
  }
@@ -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,10 @@ 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
1756
 
1757
1757
  var MAX_ATTEMPTS = 3;
1758
1758
  var useOTPHandler = function (_a) {
@@ -1787,9 +1787,7 @@ var useOTPHandler = function (_a) {
1787
1787
  MFACode: authenticationValue,
1788
1788
  appCode: appCode,
1789
1789
  }, {
1790
- headers: {
1791
- "X-Device-ID": GenerateDeviceId(),
1792
- },
1790
+ headers: APIHeaders,
1793
1791
  timeout: 605000,
1794
1792
  })];
1795
1793
  case 2:
@@ -1852,6 +1850,78 @@ var useOTPHandler = function (_a) {
1852
1850
  remainingAttempts: MAX_ATTEMPTS - attemptCount,
1853
1851
  };
1854
1852
  };
1853
+ var useCredentialsHandler = function (onAuthComplete) {
1854
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
1855
+ var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1856
+ var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1857
+ var handleSubmitCredentials = useMemo(function () {
1858
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
1859
+ var currentAttempt, response, error_2, currentAttempt;
1860
+ return __generator(this, function (_a) {
1861
+ switch (_a.label) {
1862
+ case 0:
1863
+ _a.trys.push([0, 2, 3, 4]);
1864
+ setLoading(true);
1865
+ currentAttempt = attemptCount + 1;
1866
+ setAttemptCount(currentAttempt);
1867
+ return [4 /*yield*/, axios.post(CredAuthEndpoint, {
1868
+ username: credentials.username,
1869
+ password: credentials.password,
1870
+ MFACode: credentials.MFACode,
1871
+ appCode: appCode,
1872
+ }, {
1873
+ headers: APIHeaders,
1874
+ timeout: 605000,
1875
+ })];
1876
+ case 1:
1877
+ response = (_a.sent()).data;
1878
+ if (response) {
1879
+ onAuthComplete(true, response);
1880
+ return [2 /*return*/, true];
1881
+ }
1882
+ else {
1883
+ if (currentAttempt >= MAX_ATTEMPTS) {
1884
+ setIsMaxAttemptsReached(true);
1885
+ onAuthComplete(false, {
1886
+ message: "Maximum attempts reached",
1887
+ });
1888
+ }
1889
+ else {
1890
+ onAuthComplete(false, response.response.data);
1891
+ }
1892
+ return [2 /*return*/, false];
1893
+ }
1894
+ case 2:
1895
+ error_2 = _a.sent();
1896
+ console.error(error_2);
1897
+ currentAttempt = attemptCount + 1;
1898
+ if (currentAttempt >= MAX_ATTEMPTS) {
1899
+ setIsMaxAttemptsReached(true);
1900
+ onAuthComplete(false, error_2.response.data);
1901
+ }
1902
+ else {
1903
+ onAuthComplete(false, error_2.response.data);
1904
+ }
1905
+ onAuthComplete(false, error_2.response.data);
1906
+ return [2 /*return*/, false];
1907
+ case 3:
1908
+ setLoading(false);
1909
+ return [7 /*endfinally*/];
1910
+ case 4: return [2 /*return*/];
1911
+ }
1912
+ });
1913
+ }); };
1914
+ }, []);
1915
+ return {
1916
+ handleSubmitCredentials: handleSubmitCredentials,
1917
+ loading: loading,
1918
+ setLoading: setLoading,
1919
+ attemptCount: attemptCount,
1920
+ isMaxAttemptsReached: isMaxAttemptsReached,
1921
+ // resetAttempts,
1922
+ remainingAttempts: MAX_ATTEMPTS - attemptCount,
1923
+ };
1924
+ };
1855
1925
 
1856
1926
  var MFAOptions = function (_a) {
1857
1927
  var onComplete = _a.onComplete, onAuthFailed = _a.onAuthFailed, MFAEndpoints = _a.MFAEndpoints, usePassKey = _a.usePassKey;
@@ -1870,46 +1940,36 @@ var MFAOptions = function (_a) {
1870
1940
  var authenticate = useWebAuthn().authenticate;
1871
1941
  var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
1872
1942
  var options, assertionResponse, error_1;
1873
- var _a, _b, _c, _d, _e, _f;
1874
- return __generator(this, function (_g) {
1875
- switch (_g.label) {
1943
+ return __generator(this, function (_a) {
1944
+ switch (_a.label) {
1876
1945
  case 0:
1877
- _g.trys.push([0, 4, , 5]);
1946
+ _a.trys.push([0, 4, , 5]);
1878
1947
  // 1. Fetch authentication challenge from your server
1879
1948
  console.log("Requesting authentication challenge from server...");
1880
1949
  return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1881
- headers: {
1882
- "X-DEVICE-ID": GenerateDeviceId(),
1883
- "X-API-VERSION": "1.0",
1884
- },
1950
+ headers: APIHeaders,
1885
1951
  })];
1886
1952
  case 1:
1887
- options = (_g.sent()).data;
1953
+ options = (_a.sent()).data;
1888
1954
  console.log("Received challenge:", options);
1889
1955
  // 2. Call the SDK to trigger the browser's passkey authentication UI
1890
1956
  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" }) }))];
1957
+ return [4 /*yield*/, authenticate(__assign(__assign({}, options), { userVerification: "discouraged" }))];
1895
1958
  case 2:
1896
- assertionResponse = _g.sent();
1959
+ assertionResponse = _a.sent();
1897
1960
  console.log("Authentication assertion received from client:", assertionResponse);
1898
1961
  // 3. Send the assertion back to the server for verification
1899
1962
  console.log("Sending assertion to server for verification...");
1900
1963
  return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1901
- headers: {
1902
- "X-DEVICE-ID": GenerateDeviceId(),
1903
- "X-API-VERSION": "1.0",
1904
- },
1964
+ headers: APIHeaders,
1905
1965
  withCredentials: true, // credentials: 'include'
1906
1966
  })];
1907
1967
  case 3:
1908
- _g.sent();
1968
+ _a.sent();
1909
1969
  toast.success("🔑 Sign-in successful!");
1910
1970
  return [3 /*break*/, 5];
1911
1971
  case 4:
1912
- error_1 = _g.sent();
1972
+ error_1 = _a.sent();
1913
1973
  console.error("Authentication failed:", error_1);
1914
1974
  toast.error("❌ Could not sign in.");
1915
1975
  return [3 /*break*/, 5];
@@ -2028,14 +2088,13 @@ var credentialsSchema = z.object({
2028
2088
  password: z.string().min(1, "Password is required"),
2029
2089
  });
2030
2090
  var ADLoginModal = function (_a) {
2031
- var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2091
+ var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
2032
2092
  var _b = useState("credentials"), step = _b[0], setStep = _b[1];
2033
2093
  var _c = useState({
2034
2094
  username: "",
2035
2095
  password: "",
2036
2096
  }), credentials = _c[0], setCredentials = _c[1];
2037
2097
  var _d = useState(""), mfaCode = _d[0], setMfaCode = _d[1];
2038
- var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
2039
2098
  var form = useForm({
2040
2099
  resolver: a$1(credentialsSchema),
2041
2100
  defaultValues: { username: "", password: "" },
@@ -2085,21 +2144,45 @@ var ADLoginModal = function (_a) {
2085
2144
  form.reset();
2086
2145
  setMfaCode("");
2087
2146
  };
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) {
2147
+ 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
2148
  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, {})] }));
2149
+ 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
2150
  } }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
2092
2151
  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, {})] }));
2152
+ 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
2153
  } }), 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
2154
  };
2096
2155
 
2097
2156
  var DefaultLoginPage = function (_a) {
2098
- var usePassKey = _a.usePassKey, MFAEndpoints = _a.MFAEndpoints, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2157
+ var usePassKey = _a.usePassKey, useADLogin = _a.useADLogin, MFAEndpoints = _a.MFAEndpoints, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps;
2158
+ var cardVariants = {
2159
+ hidden: { opacity: 0, scale: 0.8, y: 50 },
2160
+ visible: {
2161
+ opacity: 1,
2162
+ scale: 1,
2163
+ y: 0,
2164
+ transition: { type: "spring", duration: 0.6 },
2165
+ },
2166
+ exit: { opacity: 0, scale: 0.8, y: -50, transition: { duration: 0.3 } },
2167
+ };
2099
2168
  var context = useCAMSContext();
2100
2169
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2101
2170
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
2102
2171
  var register = useWebAuthn().register;
2172
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
2173
+ return __generator(this, function (_a) {
2174
+ console.log(data);
2175
+ if (state && data) {
2176
+ context.isAuthenticated = true;
2177
+ context.requiresMFA = false;
2178
+ context.setUserProfile({
2179
+ type: "AUTH_SUCCESS",
2180
+ userProfile: __assign({}, data),
2181
+ });
2182
+ }
2183
+ return [2 /*return*/];
2184
+ });
2185
+ }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2103
2186
  var handleMSALLogin = function () {
2104
2187
  if (authMode === "MSAL") {
2105
2188
  login();
@@ -2109,16 +2192,6 @@ var DefaultLoginPage = function (_a) {
2109
2192
  console.warn("Regular CAMS login requires configuration");
2110
2193
  }
2111
2194
  };
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
2195
  var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2123
2196
  var options, attestationResponse, error_1;
2124
2197
  return __generator(this, function (_a) {
@@ -2128,10 +2201,7 @@ var DefaultLoginPage = function (_a) {
2128
2201
  // 1. Fetch challenge from your server
2129
2202
  console.log("Requesting registration challenge from server...");
2130
2203
  return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2131
- headers: {
2132
- "X-DEVICE-ID": GenerateDeviceId(),
2133
- "X-API-VERSION": "1.0",
2134
- },
2204
+ headers: APIHeaders,
2135
2205
  })];
2136
2206
  case 1:
2137
2207
  options = (_a.sent()).data;
@@ -2145,10 +2215,7 @@ var DefaultLoginPage = function (_a) {
2145
2215
  // 3. Send the response back to the server for verification
2146
2216
  console.log("Sending attestation to server for verification...");
2147
2217
  return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2148
- headers: {
2149
- "X-DEVICE-ID": GenerateDeviceId(),
2150
- "X-API-VERSION": "1.0",
2151
- },
2218
+ headers: APIHeaders,
2152
2219
  withCredentials: true, // credentials: 'include'
2153
2220
  })];
2154
2221
  case 3:
@@ -2168,11 +2235,15 @@ var DefaultLoginPage = function (_a) {
2168
2235
  // variant="outline"
2169
2236
  , {
2170
2237
  // 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) {
2238
+ 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
2239
+ ? "Logging in..."
2240
+ : "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
2241
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2173
2242
  return __generator(this, function (_c) {
2174
2243
  // Implement your AD login logic here
2175
2244
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2245
+ // Example: await adLoginService(username, password, mfaCode);
2246
+ handleSubmitCredentials(CredentialsAuthEndpoint !== null && CredentialsAuthEndpoint !== void 0 ? CredentialsAuthEndpoint : "/api/auth/validate", { username: username, password: password, MFACode: MFACode }, context.appCode);
2176
2247
  return [2 /*return*/];
2177
2248
  });
2178
2249
  }); } })] }));
@@ -2195,7 +2266,7 @@ var MFAGate = function (_a) {
2195
2266
  // loginComponent: LoginComponent = DefaultLoginPage,
2196
2267
  _c = _a.usePassKey,
2197
2268
  // loginComponent: LoginComponent = DefaultLoginPage,
2198
- usePassKey = _c === void 0 ? false : _c, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2269
+ 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
2270
  var context = useCAMSContext();
2200
2271
  var validatedMFAEndpoints = useMemo(function () {
2201
2272
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
@@ -2220,8 +2291,10 @@ var MFAGate = function (_a) {
2220
2291
  });
2221
2292
  }); }, [context.logout]);
2222
2293
  Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2294
+ if (useADLogin && !CredentialsAuthEndpoint)
2295
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2223
2296
  if (!validatedMFAEndpoints)
2224
- return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA configuration." });
2297
+ return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
2225
2298
  if (context.authMode !== "MSAL")
2226
2299
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2227
2300
  if (context.isLoading)
@@ -2230,7 +2303,7 @@ var MFAGate = function (_a) {
2230
2303
  return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2231
2304
  }
2232
2305
  if (!context.isAuthenticated) {
2233
- return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps }));
2306
+ return (jsxRuntimeExports.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
2234
2307
  }
2235
2308
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2236
2309
  };