@nibssplc/cams-sdk-react 1.0.0-rc.3 → 1.0.0-rc.30

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,159 @@ 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';
22
+
23
+ // Crypto polyfill for MSAL browser compatibility
24
+ if (typeof window !== 'undefined') {
25
+ // Ensure crypto object exists
26
+ if (!window.crypto) {
27
+ try {
28
+ Object.defineProperty(window, 'crypto', {
29
+ value: {},
30
+ writable: true,
31
+ configurable: true
32
+ });
33
+ }
34
+ catch (e) {
35
+ // Ignore if crypto cannot be defined
36
+ }
37
+ }
38
+ // Polyfill getRandomValues
39
+ if (window.crypto && !window.crypto.getRandomValues) {
40
+ try {
41
+ Object.defineProperty(window.crypto, 'getRandomValues', {
42
+ value: function (array) {
43
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
44
+ for (var i = 0; i < bytes.length; i++) {
45
+ bytes[i] = Math.floor(Math.random() * 256);
46
+ }
47
+ return array;
48
+ },
49
+ writable: true,
50
+ configurable: true
51
+ });
52
+ }
53
+ catch (e) {
54
+ // Ignore if getRandomValues cannot be defined
55
+ }
56
+ }
57
+ // Polyfill crypto.subtle with SHA-256 (handles both undefined and null in non-HTTPS contexts)
58
+ var needsSubtlePolyfill = window.crypto && (!window.crypto.subtle ||
59
+ window.location.protocol === 'http:' ||
60
+ window.location.hostname === 'localhost' ||
61
+ window.location.hostname === '127.0.0.1');
62
+ if (needsSubtlePolyfill) {
63
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
64
+ var bytes, hash, k, ml, msg, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
65
+ return __generator(this, function (_a) {
66
+ bytes = new Uint8Array(data);
67
+ hash = new Uint32Array(8);
68
+ k = new Uint32Array([
69
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
70
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
71
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
72
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
73
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
74
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
75
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
76
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
77
+ ]);
78
+ hash[0] = 0x6a09e667;
79
+ hash[1] = 0xbb67ae85;
80
+ hash[2] = 0x3c6ef372;
81
+ hash[3] = 0xa54ff53a;
82
+ hash[4] = 0x510e527f;
83
+ hash[5] = 0x9b05688c;
84
+ hash[6] = 0x1f83d9ab;
85
+ hash[7] = 0x5be0cd19;
86
+ ml = bytes.length * 8;
87
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
88
+ msg.set(bytes);
89
+ msg[bytes.length] = 0x80;
90
+ new DataView(msg.buffer).setUint32(msg.length - 4, ml, false);
91
+ for (i = 0; i < msg.length; i += 64) {
92
+ w = new Uint32Array(64);
93
+ for (j = 0; j < 16; j++)
94
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
95
+ for (j = 16; j < 64; j++) {
96
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^ (w[j - 15] >>> 3);
97
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^ (w[j - 2] >>> 10);
98
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
99
+ }
100
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
101
+ for (j = 0; j < 64; j++) {
102
+ S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
103
+ ch = (e & f) ^ (~e & g);
104
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
105
+ S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
106
+ maj = (a & b) ^ (a & c) ^ (b & c);
107
+ temp2 = (S0 + maj) >>> 0;
108
+ h = g;
109
+ g = f;
110
+ f = e;
111
+ e = (d + temp1) >>> 0;
112
+ d = c;
113
+ c = b;
114
+ b = a;
115
+ a = (temp1 + temp2) >>> 0;
116
+ }
117
+ hash[0] = (hash[0] + a) >>> 0;
118
+ hash[1] = (hash[1] + b) >>> 0;
119
+ hash[2] = (hash[2] + c) >>> 0;
120
+ hash[3] = (hash[3] + d) >>> 0;
121
+ hash[4] = (hash[4] + e) >>> 0;
122
+ hash[5] = (hash[5] + f) >>> 0;
123
+ hash[6] = (hash[6] + g) >>> 0;
124
+ hash[7] = (hash[7] + h) >>> 0;
125
+ }
126
+ result = new Uint8Array(32);
127
+ for (i = 0; i < 8; i++)
128
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
129
+ return [2 /*return*/, result.buffer];
130
+ });
131
+ }); };
132
+ try {
133
+ Object.defineProperty(window.crypto, 'subtle', {
134
+ value: {
135
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
136
+ var alg;
137
+ return __generator(this, function (_a) {
138
+ alg = typeof algorithm === 'string' ? algorithm : algorithm.name;
139
+ if (alg === 'SHA-256')
140
+ return [2 /*return*/, sha256_1(data)];
141
+ console.error("Unsupported crypto algorithm: ".concat(alg));
142
+ throw new Error("Unsupported algorithm: ".concat(alg));
143
+ });
144
+ }); }
145
+ },
146
+ writable: true,
147
+ configurable: true
148
+ });
149
+ }
150
+ catch (e) {
151
+ // Ignore if subtle cannot be defined
152
+ }
153
+ }
154
+ // Polyfill randomUUID
155
+ if (window.crypto && !window.crypto.randomUUID) {
156
+ try {
157
+ Object.defineProperty(window.crypto, 'randomUUID', {
158
+ value: function () {
159
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
160
+ var r = (Math.random() * 16) | 0;
161
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
162
+ return v.toString(16);
163
+ });
164
+ },
165
+ writable: true,
166
+ configurable: true
167
+ });
168
+ }
169
+ catch (e) {
170
+ // Ignore if randomUUID cannot be defined
171
+ }
172
+ }
173
+ }
21
174
 
22
175
  /******************************************************************************
23
176
  Copyright (c) Microsoft Corporation.
@@ -59,7 +212,7 @@ function __rest(s, e) {
59
212
  return t;
60
213
  }
61
214
 
62
- function __awaiter(thisArg, _arguments, P, generator) {
215
+ function __awaiter$1(thisArg, _arguments, P, generator) {
63
216
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
64
217
  return new (P || (P = Promise))(function (resolve, reject) {
65
218
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -69,7 +222,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
69
222
  });
70
223
  }
71
224
 
72
- function __generator(thisArg, body) {
225
+ function __generator$1(thisArg, body) {
73
226
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
74
227
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
75
228
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -166,10 +319,10 @@ function useCAMSAuth(options) {
166
319
  }
167
320
  }
168
321
  }, [options.storageKey]);
169
- var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
322
+ var login = useCallback(function (config) { return __awaiter$1(_this, void 0, void 0, function () {
170
323
  var loginConfig, userProfile, err_1, e, isPopupClosedError, restoredToken, userProfile;
171
324
  var _a, _b, _c;
172
- return __generator(this, function (_d) {
325
+ return __generator$1(this, function (_d) {
173
326
  switch (_d.label) {
174
327
  case 0:
175
328
  if (!sessionManagerRef.current)
@@ -217,8 +370,8 @@ function useCAMSAuth(options) {
217
370
  }
218
371
  });
219
372
  }); }, [options.idleTimeout]);
220
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
373
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
374
+ return __generator$1(this, function (_a) {
222
375
  switch (_a.label) {
223
376
  case 0:
224
377
  if (!sessionManagerRef.current)
@@ -248,11 +401,13 @@ function useCAMSAuth(options) {
248
401
  };
249
402
  }
250
403
 
251
- var setCookie$1 = function (name, value, days) {
404
+ var setCookie = function (name, value, days) {
405
+ if (days === void 0) { days = 1; }
252
406
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
407
+ console.log("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
253
408
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
254
409
  };
255
- var getCookie$1 = function (name) {
410
+ var getCookie = function (name) {
256
411
  var _a;
257
412
  return ((_a = document.cookie
258
413
  .split("; ")
@@ -263,23 +418,24 @@ var getCookie$1 = function (name) {
263
418
  .split("=")[1])
264
419
  : null;
265
420
  };
266
- var deleteCookie$1 = function (name) {
421
+ var deleteCookie = function (name) {
267
422
  document.cookie = name + "=; Max-Age=-99999999; path=/";
268
423
  };
269
424
 
270
425
  function useCAMSMSALAuth(options) {
271
426
  var _this = this;
272
- var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
273
- var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
427
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
428
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
429
+ var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
274
430
  var account = useAccount(accounts[0] || {});
275
- var _b = useState(null), error = _b[0], setError = _b[1];
276
- var _c = useState(""), idToken = _c[0], setIdToken = _c[1];
277
- var _d = useState(""), accessToken = _d[0], setAccessToken = _d[1];
278
- var _e = useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
279
- var _f = useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
431
+ var _c = useState(null), error = _c[0], setError = _c[1];
432
+ var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
433
+ var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
434
+ var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
435
+ var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
280
436
  var isLoading = inProgress !== InteractionStatus.None;
281
437
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
282
- var scopes = options.scopes || ["openid", "profile", "email"];
438
+ var scopes = optScopes || ["openid", "profile", "email"];
283
439
  var isTokenValid = function (token) {
284
440
  try {
285
441
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -303,15 +459,14 @@ function useCAMSMSALAuth(options) {
303
459
  var mfaConfig = {
304
460
  accessToken: accessToken_1,
305
461
  idToken: idToken_1,
306
- appCode: options.appCode,
462
+ appCode: appCode,
307
463
  provider: "MSAL",
308
- apiEndpoint: options.MFAEndpoint,
464
+ apiEndpoint: MFAEndpoint,
309
465
  };
310
466
  var authenticator = new CAMSMFAAuthenticator(mfaConfig);
311
467
  setMfaAuthenticator(authenticator);
312
468
  setRequiresMFA(true);
313
469
  }
314
- Logger.debug("App Code", { ">>>": options.appCode });
315
470
  }
316
471
  else {
317
472
  localStorage.removeItem(storageKey);
@@ -353,22 +508,26 @@ function useCAMSMSALAuth(options) {
353
508
  // };
354
509
  // handleRedirect();
355
510
  // }, []);
356
- var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
511
+ var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
357
512
  var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
358
- var _a, _b, _c, _d;
359
- return __generator(this, function (_e) {
360
- switch (_e.label) {
513
+ var _a;
514
+ return __generator$1(this, function (_b) {
515
+ switch (_b.label) {
361
516
  case 0:
517
+ if (inProgress !== InteractionStatus.None) {
518
+ Logger.warn("Authentication already in progress, ignoring duplicate call");
519
+ return [2 /*return*/];
520
+ }
362
521
  setError(null);
363
- _e.label = 1;
522
+ _b.label = 1;
364
523
  case 1:
365
- _e.trys.push([1, 3, , 4]);
524
+ _b.trys.push([1, 3, , 4]);
366
525
  return [4 /*yield*/, instance.loginPopup({
367
526
  scopes: scopes,
368
- prompt: options.prompt || "login",
527
+ prompt: prompt || "login",
369
528
  })];
370
529
  case 2:
371
- response = _e.sent();
530
+ response = _b.sent();
372
531
  console.log("Login Token response:", {
373
532
  accessToken: response.accessToken,
374
533
  idToken: response.idToken,
@@ -378,9 +537,9 @@ function useCAMSMSALAuth(options) {
378
537
  mfaConfig = {
379
538
  accessToken: response.accessToken,
380
539
  idToken: response.idToken,
381
- appCode: options.appCode,
540
+ appCode: appCode,
382
541
  provider: "MSAL",
383
- apiEndpoint: options.MFAEndpoint,
542
+ apiEndpoint: MFAEndpoint,
384
543
  };
385
544
  authenticator = new CAMSMFAAuthenticator(mfaConfig);
386
545
  setMfaAuthenticator(authenticator);
@@ -394,10 +553,15 @@ function useCAMSMSALAuth(options) {
394
553
  idToken: response.idToken,
395
554
  }));
396
555
  }
397
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
556
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
398
557
  return [3 /*break*/, 4];
399
558
  case 3:
400
- err_1 = _e.sent();
559
+ err_1 = _b.sent();
560
+ // Handle interaction_in_progress error
561
+ if (err_1.errorCode === "interaction_in_progress") {
562
+ Logger.warn("Interaction already in progress, please wait");
563
+ return [2 /*return*/];
564
+ }
401
565
  // Handle user cancellation gracefully
402
566
  if (err_1.errorCode === "user_cancelled") {
403
567
  Logger.error("User cancelled login");
@@ -406,22 +570,22 @@ function useCAMSMSALAuth(options) {
406
570
  }
407
571
  // If popup is blocked
408
572
  if (err_1.errorCode === "popup_window_error" ||
409
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
573
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
410
574
  camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
411
575
  setError(camsError_1);
412
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
576
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
413
577
  return [2 /*return*/];
414
578
  }
415
579
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
416
580
  setError(camsError);
417
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
581
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
418
582
  return [3 /*break*/, 4];
419
583
  case 4: return [2 /*return*/];
420
584
  }
421
585
  });
422
- }); }, [instance, scopes, options]);
423
- var completeMFA = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
424
- return __generator(this, function (_a) {
586
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
587
+ var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
588
+ return __generator$1(this, function (_a) {
425
589
  if (!mfaAuthenticator) {
426
590
  throw new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "MFA Authenticator not initialized");
427
591
  }
@@ -435,7 +599,7 @@ function useCAMSMSALAuth(options) {
435
599
  accessToken: accessToken,
436
600
  idToken: idToken,
437
601
  }));
438
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
602
+ setCookie("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
439
603
  setRequiresMFA(false);
440
604
  // Set requiresMFA to false after storage update
441
605
  Logger.debug("MFA completed successfully, storage updated", {
@@ -454,9 +618,9 @@ function useCAMSMSALAuth(options) {
454
618
  }
455
619
  return [2 /*return*/];
456
620
  });
457
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
458
- var sendEmailOTP = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
459
- return __generator(this, function (_a) {
621
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
622
+ var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
623
+ return __generator$1(this, function (_a) {
460
624
  switch (_a.label) {
461
625
  case 0:
462
626
  if (!mfaAuthenticator) {
@@ -467,9 +631,9 @@ function useCAMSMSALAuth(options) {
467
631
  }
468
632
  });
469
633
  }); }, [mfaAuthenticator]);
470
- var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
634
+ var logout = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
471
635
  var err_2, camsError;
472
- return __generator(this, function (_a) {
636
+ return __generator$1(this, function (_a) {
473
637
  switch (_a.label) {
474
638
  case 0:
475
639
  _a.trys.push([0, 2, , 3]);
@@ -505,12 +669,13 @@ function useCAMSMSALAuth(options) {
505
669
  error: error,
506
670
  idToken: idToken,
507
671
  accessToken: accessToken,
508
- appCode: options.appCode,
672
+ appCode: appCode,
509
673
  mfaAuthenticator: mfaAuthenticator,
510
674
  requiresMFA: requiresMFA,
511
675
  completeMFA: completeMFA,
512
676
  sendEmailOTP: sendEmailOTP,
513
677
  setRequiresMFA: setRequiresMFA,
678
+ activeCookiePeriod: activeCookiePeriod,
514
679
  };
515
680
  }
516
681
 
@@ -553,10 +718,10 @@ function arrayBufferToBase64url(buffer) {
553
718
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
554
719
  */
555
720
  function register(options) {
556
- return __awaiter(this, void 0, void 0, function () {
721
+ return __awaiter$1(this, void 0, void 0, function () {
557
722
  var createOptions, credential, publicKeyCredential, attestationResponse, transports, err_1;
558
723
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
559
- return __generator(this, function (_k) {
724
+ return __generator$1(this, function (_k) {
560
725
  switch (_k.label) {
561
726
  case 0:
562
727
  _k.trys.push([0, 2, , 3]);
@@ -614,10 +779,10 @@ function register(options) {
614
779
  * @returns A promise that resolves to a JSON-serializable representation of the PublicKeyCredential.
615
780
  */
616
781
  function authenticate(options) {
617
- return __awaiter(this, void 0, void 0, function () {
782
+ return __awaiter$1(this, void 0, void 0, function () {
618
783
  var getOptions, credential, publicKeyCredential, assertionResponse;
619
784
  var _a;
620
- return __generator(this, function (_b) {
785
+ return __generator$1(this, function (_b) {
621
786
  switch (_b.label) {
622
787
  case 0:
623
788
  getOptions = __assign(__assign({}, options), { challenge: base64urlToArrayBuffer(options.challenge), allowCredentials: (_a = options.allowCredentials) === null || _a === void 0 ? void 0 : _a.map(function (cred) { return (__assign(__assign({}, cred), { id: base64urlToArrayBuffer(cred.id) })); }) });
@@ -1103,24 +1268,6 @@ function ProtectedRoute(_a) {
1103
1268
  }
1104
1269
 
1105
1270
  var CAMSMSALContext = createContext(null);
1106
- var setCookie = function (name, value, days) {
1107
- var expires = new Date(Date.now() + days * 864e5).toUTCString();
1108
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1109
- };
1110
- var getCookie = function (name) {
1111
- var _a;
1112
- return ((_a = document.cookie
1113
- .split("; ")
1114
- .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
1115
- ? decodeURIComponent(document.cookie
1116
- .split("; ")
1117
- .find(function (row) { return row.startsWith(name + "="); })
1118
- .split("=")[1])
1119
- : null;
1120
- };
1121
- var deleteCookie = function (name) {
1122
- document.cookie = name + "=; Max-Age=-99999999; path=/";
1123
- };
1124
1271
  var isTokenValid = function (token) {
1125
1272
  try {
1126
1273
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -1169,7 +1316,7 @@ function CAMSMSALProviderInner(_a) {
1169
1316
  localStorage.setItem(auth.storageKey, JSON.stringify({
1170
1317
  accessToken: auth.accessToken,
1171
1318
  idToken: auth.idToken,
1172
- appCode: auth.appCode
1319
+ appCode: auth.appCode,
1173
1320
  }));
1174
1321
  }
1175
1322
  }, [auth.accessToken, auth.idToken, auth.storageKey]);
@@ -1185,8 +1332,8 @@ function CAMSMSALProviderInner(_a) {
1185
1332
  }
1186
1333
  }, [userProfile, profileStorageKey]);
1187
1334
  // Enhanced logout that also clears profile
1188
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1189
- return __generator(this, function (_a) {
1335
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1336
+ return __generator$1(this, function (_a) {
1190
1337
  switch (_a.label) {
1191
1338
  case 0: return [4 /*yield*/, auth.logout()];
1192
1339
  case 1:
@@ -1253,7 +1400,7 @@ function CAMSProviderCore(props) {
1253
1400
  if (typeof window === "undefined")
1254
1401
  return null;
1255
1402
  try {
1256
- var storedProfile = getCookie$1(profileStorageKey);
1403
+ var storedProfile = getCookie(profileStorageKey);
1257
1404
  return storedProfile ? JSON.parse(storedProfile) : null;
1258
1405
  }
1259
1406
  catch (_a) {
@@ -1263,7 +1410,7 @@ function CAMSProviderCore(props) {
1263
1410
  var _a = useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1264
1411
  useEffect(function () {
1265
1412
  if (typeof window !== "undefined") {
1266
- var storedProfile = getCookie$1(profileStorageKey);
1413
+ var storedProfile = getCookie(profileStorageKey);
1267
1414
  if (storedProfile) {
1268
1415
  try {
1269
1416
  setUserProfile(JSON.parse(storedProfile));
@@ -1275,22 +1422,22 @@ function CAMSProviderCore(props) {
1275
1422
  useEffect(function () {
1276
1423
  if (typeof window !== "undefined") {
1277
1424
  if (userProfile) {
1278
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1425
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
1279
1426
  }
1280
1427
  else {
1281
- deleteCookie$1(profileStorageKey);
1428
+ deleteCookie(profileStorageKey);
1282
1429
  }
1283
1430
  }
1284
1431
  }, [userProfile, profileStorageKey]);
1285
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1286
- return __generator(this, function (_a) {
1432
+ var enhancedLogout = function () { return __awaiter$1(_this, void 0, void 0, function () {
1433
+ return __generator$1(this, function (_a) {
1287
1434
  switch (_a.label) {
1288
1435
  case 0: return [4 /*yield*/, auth.logout()];
1289
1436
  case 1:
1290
1437
  _a.sent();
1291
1438
  setUserProfile(null);
1292
1439
  if (typeof window !== "undefined") {
1293
- deleteCookie$1(profileStorageKey);
1440
+ deleteCookie(profileStorageKey);
1294
1441
  }
1295
1442
  return [2 /*return*/];
1296
1443
  }
@@ -1326,7 +1473,8 @@ function CAMSProviderCore(props) {
1326
1473
  userProfile,
1327
1474
  ]);
1328
1475
  var value = useMemo(function () {
1329
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1476
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1477
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1330
1478
  }, [auth, userProfile, mode]);
1331
1479
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1332
1480
  }
@@ -1334,7 +1482,7 @@ function UnifiedCAMSProvider(props) {
1334
1482
  // Validate appCode is a valid GUID
1335
1483
  var appCodeValidation = GuidSchema.safeParse(props.appCode);
1336
1484
  if (!appCodeValidation.success) {
1337
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1485
+ throw new Error("Invalid CAS APP CODE: ".concat(appCodeValidation.error.issues[0].message));
1338
1486
  }
1339
1487
  if (props.mode === "MSAL") {
1340
1488
  var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
@@ -1702,7 +1850,7 @@ styleInject(css_248z);
1702
1850
 
1703
1851
  var LoadingSpinner = function (_a) {
1704
1852
  var loadingText = _a.loadingText;
1705
- 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..." }))] }));
1853
+ 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..." }))] }));
1706
1854
  };
1707
1855
 
1708
1856
  var AuthSuccessAnimation = function (_a) {
@@ -1754,15 +1902,36 @@ var APIHeaders = {
1754
1902
  "X-API-VERSION": "1.0",
1755
1903
  };
1756
1904
 
1905
+ // Creates an Axios instance with a base URL determined by the environment (production or development).
1906
+ var axiosInstance = axios.create({
1907
+ httpsAgent: new https.Agent({ rejectUnauthorized: false }),
1908
+ headers: __assign({ "Content-Type": "application/json" }, APIHeaders),
1909
+ });
1910
+ // Intercepts outgoing requests to add authorization token, version header, and timeout settings.
1911
+ axiosInstance.interceptors.request.use(function (config) {
1912
+ var _a;
1913
+ config.timeout = Number((_a = process.env.NEXT_PUBLIC_API_TIMEOUT) !== null && _a !== void 0 ? _a : 605000);
1914
+ config.timeoutErrorMessage = "Operation Timed Out"; // Custom error message for timeouts.
1915
+ return config; // Returns the modified request configuration.
1916
+ }, function (axiosError) {
1917
+ var _a, _b;
1918
+ // Handles request errors.
1919
+ return {
1920
+ status: (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status, // Extracts HTTP status from the error response.
1921
+ message: axiosError.message, // Extracts the error message.
1922
+ data: (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data, // Extracts response data from the error.
1923
+ };
1924
+ });
1925
+
1757
1926
  var MAX_ATTEMPTS = 3;
1758
1927
  var useOTPHandler = function (_a) {
1759
1928
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1760
1929
  var _b = useState(false), loading = _b[0], setLoading = _b[1];
1761
1930
  var _c = useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1762
1931
  var _d = useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1763
- var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
1932
+ var handleSubmitOTP = useMemo(function () { return function (authenticationValue) { return __awaiter$1(void 0, void 0, void 0, function () {
1764
1933
  var currentAttempt, response, error_1, currentAttempt;
1765
- return __generator(this, function (_a) {
1934
+ return __generator$1(this, function (_a) {
1766
1935
  switch (_a.label) {
1767
1936
  case 0:
1768
1937
  if (isMaxAttemptsReached) {
@@ -1779,16 +1948,13 @@ var useOTPHandler = function (_a) {
1779
1948
  setAttemptCount(currentAttempt);
1780
1949
  if (authenticationType === null)
1781
1950
  return [2 /*return*/, false];
1782
- return [4 /*yield*/, axios.post(MFAEndpoint || "/api/auth/verify-mfa", {
1951
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoint || "/api/auth/verify-mfa", {
1783
1952
  provider: provider,
1784
1953
  accessToken: accessToken,
1785
1954
  idToken: idToken,
1786
1955
  authenticationType: authenticationType,
1787
1956
  MFACode: authenticationValue,
1788
1957
  appCode: appCode,
1789
- }, {
1790
- headers: APIHeaders,
1791
- timeout: 605000,
1792
1958
  })];
1793
1959
  case 2:
1794
1960
  response = (_a.sent()).data;
@@ -1855,23 +2021,20 @@ var useCredentialsHandler = function (onAuthComplete) {
1855
2021
  var _b = useState(0), attemptCount = _b[0], setAttemptCount = _b[1];
1856
2022
  var _c = useState(false), isMaxAttemptsReached = _c[0], setIsMaxAttemptsReached = _c[1];
1857
2023
  var handleSubmitCredentials = useMemo(function () {
1858
- return function (CredAuthEndpoint, credentials, appCode) { return __awaiter(void 0, void 0, void 0, function () {
2024
+ return function (CredAuthEndpoint, credentials, appCode) { return __awaiter$1(void 0, void 0, void 0, function () {
1859
2025
  var currentAttempt, response, error_2, currentAttempt;
1860
- return __generator(this, function (_a) {
2026
+ return __generator$1(this, function (_a) {
1861
2027
  switch (_a.label) {
1862
2028
  case 0:
1863
2029
  _a.trys.push([0, 2, 3, 4]);
1864
2030
  setLoading(true);
1865
2031
  currentAttempt = attemptCount + 1;
1866
2032
  setAttemptCount(currentAttempt);
1867
- return [4 /*yield*/, axios.post(CredAuthEndpoint, {
2033
+ return [4 /*yield*/, axiosInstance.post(CredAuthEndpoint, {
1868
2034
  username: credentials.username,
1869
2035
  password: credentials.password,
1870
2036
  MFACode: credentials.MFACode,
1871
2037
  appCode: appCode,
1872
- }, {
1873
- headers: APIHeaders,
1874
- timeout: 605000,
1875
2038
  })];
1876
2039
  case 1:
1877
2040
  response = (_a.sent()).data;
@@ -1932,23 +2095,21 @@ var MFAOptions = function (_a) {
1932
2095
  var context = useCAMSContext();
1933
2096
  var _f = context.authMode === "MSAL" && "sendEmailOTP" in context
1934
2097
  ? context
1935
- : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2098
+ : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter$1(void 0, void 0, void 0, function () { return __generator$1(this, function (_a) {
1936
2099
  return [2 /*return*/];
1937
2100
  }); }); } }, sendEmailOTP = _f.sendEmailOTP, completeMFA = _f.completeMFA, logout = _f.logout;
1938
2101
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1939
2102
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1940
2103
  var authenticate = useWebAuthn().authenticate;
1941
- var handleFIDOLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
2104
+ var handleFIDOLogin = function () { return __awaiter$1(void 0, void 0, void 0, function () {
1942
2105
  var options, assertionResponse, error_1;
1943
- return __generator(this, function (_a) {
2106
+ return __generator$1(this, function (_a) {
1944
2107
  switch (_a.label) {
1945
2108
  case 0:
1946
2109
  _a.trys.push([0, 4, , 5]);
1947
2110
  // 1. Fetch authentication challenge from your server
1948
2111
  console.log("Requesting authentication challenge from server...");
1949
- return [4 /*yield*/, axios.post(MFAEndpoints.RetrieveAuthChallenge, {}, {
1950
- headers: APIHeaders,
1951
- })];
2112
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RetrieveAuthChallenge, {})];
1952
2113
  case 1:
1953
2114
  options = (_a.sent()).data;
1954
2115
  console.log("Received challenge:", options);
@@ -1960,10 +2121,7 @@ var MFAOptions = function (_a) {
1960
2121
  console.log("Authentication assertion received from client:", assertionResponse);
1961
2122
  // 3. Send the assertion back to the server for verification
1962
2123
  console.log("Sending assertion to server for verification...");
1963
- return [4 /*yield*/, axios.post(MFAEndpoints.AuthChallengeVerify, assertionResponse, {
1964
- headers: APIHeaders,
1965
- withCredentials: true, // credentials: 'include'
1966
- })];
2124
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.AuthChallengeVerify, assertionResponse)];
1967
2125
  case 3:
1968
2126
  _a.sent();
1969
2127
  toast.success("🔑 Sign-in successful!");
@@ -2025,12 +2183,12 @@ var MFAOptions = function (_a) {
2025
2183
  }
2026
2184
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
2027
2185
  if (!authType) {
2028
- content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter(void 0, void 0, void 0, function () {
2186
+ content = (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center mb-6", children: "Choose your preferred authentication method:" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3", children: [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 () { return __awaiter$1(void 0, void 0, void 0, function () {
2029
2187
  var success;
2030
- return __generator(this, function (_a) {
2188
+ return __generator$1(this, function (_a) {
2031
2189
  switch (_a.label) {
2032
2190
  case 0:
2033
- resetAttempts();
2191
+ // resetAttempts();
2034
2192
  setAuthType("EmailOTP");
2035
2193
  setOtpVisible(true);
2036
2194
  if (!sendEmailOTP) return [3 /*break*/, 2];
@@ -2047,7 +2205,6 @@ var MFAOptions = function (_a) {
2047
2205
  }
2048
2206
  });
2049
2207
  }); }, 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 () {
2050
- resetAttempts();
2051
2208
  setAuthType("AuthenticatorCode");
2052
2209
  setOtpVisible(true);
2053
2210
  }, 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",
@@ -2056,7 +2213,7 @@ var MFAOptions = function (_a) {
2056
2213
  // setAuthType("AuthenticatorCode");
2057
2214
  // setOtpVisible(true);
2058
2215
  // }}
2059
- 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" })] })] }))] })] }));
2216
+ 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" })] })] }))] })] }));
2060
2217
  }
2061
2218
  else if (authType === "EmailOTP") {
2062
2219
  content = (jsxRuntimeExports.jsx(Dialog, { open: otpVisible, onOpenChange: function () {
@@ -2099,16 +2256,16 @@ var ADLoginModal = function (_a) {
2099
2256
  resolver: a$1(credentialsSchema),
2100
2257
  defaultValues: { username: "", password: "" },
2101
2258
  });
2102
- var handleCredentialsSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
2103
- return __generator(this, function (_a) {
2259
+ var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
2260
+ return __generator$1(this, function (_a) {
2104
2261
  setCredentials(values);
2105
2262
  setStep("mfa");
2106
2263
  return [2 /*return*/];
2107
2264
  });
2108
2265
  }); };
2109
- var handleMFASubmit = function (code) { return __awaiter(void 0, void 0, void 0, function () {
2266
+ var handleMFASubmit = function (code) { return __awaiter$1(void 0, void 0, void 0, function () {
2110
2267
  var error_1;
2111
- return __generator(this, function (_a) {
2268
+ return __generator$1(this, function (_a) {
2112
2269
  switch (_a.label) {
2113
2270
  case 0:
2114
2271
  setIsLoading(true);
@@ -2169,8 +2326,8 @@ var DefaultLoginPage = function (_a) {
2169
2326
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
2170
2327
  var _b = useState(false), showADModal = _b[0], setShowADModal = _b[1];
2171
2328
  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) {
2329
+ var _c = useCredentialsHandler(function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
2330
+ return __generator$1(this, function (_a) {
2174
2331
  console.log(data);
2175
2332
  if (state && data) {
2176
2333
  context.isAuthenticated = true;
@@ -2184,6 +2341,10 @@ var DefaultLoginPage = function (_a) {
2184
2341
  });
2185
2342
  }); }), handleSubmitCredentials = _c.handleSubmitCredentials, isCredAuthLoading = _c.loading, setIsCredAuthLoading = _c.setLoading;
2186
2343
  var handleMSALLogin = function () {
2344
+ if (typeof window !== "undefined" && !window.crypto) {
2345
+ toast.error("Crypto API not available. Please use a modern browser.");
2346
+ return;
2347
+ }
2187
2348
  if (authMode === "MSAL") {
2188
2349
  login();
2189
2350
  }
@@ -2192,17 +2353,15 @@ var DefaultLoginPage = function (_a) {
2192
2353
  console.warn("Regular CAMS login requires configuration");
2193
2354
  }
2194
2355
  };
2195
- var handleRegister = function (data) { return __awaiter(void 0, void 0, void 0, function () {
2356
+ var handleRegister = function (data) { return __awaiter$1(void 0, void 0, void 0, function () {
2196
2357
  var options, attestationResponse, error_1;
2197
- return __generator(this, function (_a) {
2358
+ return __generator$1(this, function (_a) {
2198
2359
  switch (_a.label) {
2199
2360
  case 0:
2200
2361
  _a.trys.push([0, 4, , 5]);
2201
2362
  // 1. Fetch challenge from your server
2202
2363
  console.log("Requesting registration challenge from server...");
2203
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data), {
2204
- headers: APIHeaders,
2205
- })];
2364
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterNewChallenge, __assign({}, data))];
2206
2365
  case 1:
2207
2366
  options = (_a.sent()).data;
2208
2367
  console.log("Received challenge:", options);
@@ -2214,10 +2373,7 @@ var DefaultLoginPage = function (_a) {
2214
2373
  console.log("Passkey created on client:", attestationResponse);
2215
2374
  // 3. Send the response back to the server for verification
2216
2375
  console.log("Sending attestation to server for verification...");
2217
- return [4 /*yield*/, axios.post(MFAEndpoints.RegisterVerify, attestationResponse, {
2218
- headers: APIHeaders,
2219
- withCredentials: true, // credentials: 'include'
2220
- })];
2376
+ return [4 /*yield*/, axiosInstance.post(MFAEndpoints.RegisterVerify + "?username=".concat(data.username), attestationResponse)];
2221
2377
  case 3:
2222
2378
  _a.sent();
2223
2379
  toast.success("✅ Registration successful! Passkey created.");
@@ -2231,15 +2387,15 @@ var DefaultLoginPage = function (_a) {
2231
2387
  }
2232
2388
  });
2233
2389
  }); };
2234
- return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-6", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Kindly use the below identity providers to authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
2390
+ return (jsxRuntimeExports.jsxs("main", { className: "min-h-screen bg-gray-50", children: [jsxRuntimeExports.jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.5 }, children: jsxRuntimeExports.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntimeExports.jsxs(motion.div, { variants: cardVariants, initial: "hidden", animate: "visible", exit: "exit", className: "w-full max-w-md p-6 space-y-4 bg-gray-50 rounded-2xl shadow-2xl --dark:bg-gray-800", children: [jsxRuntimeExports.jsxs(CardHeader, { className: "text-center space-y-3", children: [jsxRuntimeExports.jsx("div", { className: "w-full flex items-center justify-center", children: jsxRuntimeExports.jsx("img", { src: NIBSSLogo, alt: "NIBSS Logo", width: 265, height: 265 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold --text-gray-900 --dark:text-white", children: "NIBSS CAMS" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-500 dark:text-gray-400 font-bold text-lg", children: "Centralized Authentication" })] }), jsxRuntimeExports.jsxs(CardAction, { className: "w-full flex flex-col items-center justify-center text-center text-gray-500 dark:text-gray-400 mb-8", children: [jsxRuntimeExports.jsx("img", { src: AuthLogo, alt: "Auth Logo", width: 365, height: 365 }), "Use Below Identity Providers To Authenticate"] }), jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsxs(Button
2235
2391
  // variant="outline"
2236
2392
  , {
2237
2393
  // variant="outline"
2238
2394
  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
2395
  ? "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) {
2396
+ : "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$1(void 0, [_a], void 0, function (_b) {
2241
2397
  var username = _b.username, password = _b.password, MFACode = _b.MFACode;
2242
- return __generator(this, function (_c) {
2398
+ return __generator$1(this, function (_c) {
2243
2399
  // Implement your AD login logic here
2244
2400
  console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
2245
2401
  // Example: await adLoginService(username, password, mfaCode);
@@ -2280,8 +2436,8 @@ var MFAGate = function (_a) {
2280
2436
  if (!success)
2281
2437
  Logger.error("MFA authentication failed");
2282
2438
  }, []);
2283
- var handleAuthFailed = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
2284
- return __generator(this, function (_a) {
2439
+ var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2440
+ return __generator$1(this, function (_a) {
2285
2441
  switch (_a.label) {
2286
2442
  case 0: return [4 /*yield*/, context.logout()];
2287
2443
  case 1:
@@ -2290,7 +2446,6 @@ var MFAGate = function (_a) {
2290
2446
  }
2291
2447
  });
2292
2448
  }); }, [context.logout]);
2293
- Logger.debug("MFA Endpoint >>>", { MFAEndpoints: MFAEndpoints });
2294
2449
  if (useADLogin && !CredentialsAuthEndpoint)
2295
2450
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2296
2451
  if (!validatedMFAEndpoints)