@nibssplc/cams-sdk-react 1.0.0-rc.82 → 1.0.0-rc.84

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,4 +1,4 @@
1
- import { Credentials } from "@nibssplc/cams-sdk";
1
+ import { type Credentials } from "@nibssplc/cams-sdk";
2
2
  interface ADLoginModalProps {
3
3
  open: boolean;
4
4
  isLoading: boolean;
package/dist/index.cjs.js CHANGED
@@ -441,11 +441,10 @@ function useCAMSMSALAuth(options) {
441
441
  var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
442
442
  var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
443
443
  var _f = React.useState(""), email = _f[0], setEmail = _f[1];
444
- // const [mfaAuthenticator, setMfaAuthenticator] =
445
- // useState<CAMSMFAAuthenticator | null>(null);
446
444
  var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
447
- var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
448
- var isAuthenticated = !!account && !!accessToken && !requiresMFA;
445
+ var _h = React.useState(false), isFetchingMFAConfig = _h[0], setIsFetchingMFAConfig = _h[1];
446
+ var isLoading = inProgress !== msalBrowser.InteractionStatus.None || isFetchingMFAConfig;
447
+ var isAuthenticated = !!account && !!accessToken;
449
448
  var scopes = optScopes || ["openid", "profile", "email"];
450
449
  var isTokenValid = function (token) {
451
450
  try {
@@ -513,9 +512,11 @@ function useCAMSMSALAuth(options) {
513
512
  APIAuthEndpoint: ValidateUserEndpoint,
514
513
  };
515
514
  authenticator = new camsSdk.CAMSMFAAuthenticator();
515
+ setIsFetchingMFAConfig(true);
516
516
  return [4 /*yield*/, authenticator.GetUserMFAConfig(mfaConfig)];
517
517
  case 3:
518
518
  userConfig = _b.sent();
519
+ setIsFetchingMFAConfig(false);
519
520
  console.log("CAMS MFA Authenticator initialized:", {
520
521
  mfaConfig: mfaConfig,
521
522
  userConfig: userConfig,
@@ -542,6 +543,7 @@ function useCAMSMSALAuth(options) {
542
543
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + userConfig.message);
543
544
  sonner.toast.error("Login failed");
544
545
  setError(camsError);
546
+ setIsFetchingMFAConfig(false);
545
547
  }
546
548
  return [3 /*break*/, 5];
547
549
  case 4:
@@ -566,6 +568,7 @@ function useCAMSMSALAuth(options) {
566
568
  }
567
569
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
568
570
  setError(camsError);
571
+ setIsFetchingMFAConfig(false);
569
572
  return [3 /*break*/, 5];
570
573
  case 5: return [2 /*return*/];
571
574
  }
@@ -1663,12 +1666,13 @@ var credentialsSchema = z.z.object({
1663
1666
  });
1664
1667
  var ADLoginModal = function (_a) {
1665
1668
  var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
1666
- var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
1667
- var _c = React.useState({
1669
+ var _b = React.useState("Credentials"), step = _b[0], setStep = _b[1];
1670
+ var _c = React.useState(false), showPassword = _c[0], setShowPassword = _c[1];
1671
+ var _d = React.useState({
1668
1672
  username: "",
1669
1673
  password: "",
1670
- }), credentials = _c[0], setCredentials = _c[1];
1671
- var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
1674
+ }), credentials = _d[0], setCredentials = _d[1];
1675
+ var _e = React.useState(""), MFACode = _e[0], setMFACode = _e[1];
1672
1676
  var form = reactHookForm.useForm({
1673
1677
  resolver: a$1(credentialsSchema),
1674
1678
  defaultValues: { username: "", password: "" },
@@ -1676,7 +1680,7 @@ var ADLoginModal = function (_a) {
1676
1680
  var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
1677
1681
  return __generator$1(this, function (_a) {
1678
1682
  setCredentials(values);
1679
- setStep("mfa");
1683
+ setStep("MFA");
1680
1684
  return [2 /*return*/];
1681
1685
  });
1682
1686
  }); };
@@ -1698,9 +1702,9 @@ var ADLoginModal = function (_a) {
1698
1702
  case 2:
1699
1703
  _a.sent();
1700
1704
  onOpenChange(false);
1701
- setStep("credentials");
1705
+ setStep("Credentials");
1702
1706
  form.reset();
1703
- setMfaCode("");
1707
+ setMFACode("");
1704
1708
  return [3 /*break*/, 5];
1705
1709
  case 3:
1706
1710
  error_1 = _a.sent();
@@ -1715,17 +1719,18 @@ var ADLoginModal = function (_a) {
1715
1719
  }); };
1716
1720
  var handleClose = function () {
1717
1721
  onOpenChange(false);
1718
- setStep("credentials");
1722
+ setStep("Credentials");
1719
1723
  form.reset();
1720
- setMfaCode("");
1724
+ setMFACode("");
1725
+ setShowPassword(false);
1721
1726
  };
1722
- return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "credentials" ? (jsxRuntime.jsx(Form, __assign({}, form, { children: jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsxRuntime.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1727
+ return (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntime.jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntime.jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "Credentials" ? (jsxRuntime.jsx(Form, __assign({}, form, { children: jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsxRuntime.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1723
1728
  var field = _a.field;
1724
1729
  return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Username" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
1725
1730
  } }), jsxRuntime.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
1726
1731
  var field = _a.field;
1727
- return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Password" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsxRuntime.jsx(FormMessage, {})] }));
1728
- } }), jsxRuntime.jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value: mfaCode, setValue: setMfaCode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntime.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1732
+ return (jsxRuntime.jsxs(FormItem, { children: [jsxRuntime.jsx(FormLabel, { children: "Password" }), jsxRuntime.jsx(FormControl, { children: jsxRuntime.jsxs("div", { className: "relative", children: [jsxRuntime.jsx(Input, __assign({ className: "h-12 pr-10", type: "password", placeholder: "Enter your password" }, field)), jsxRuntime.jsx("button", { type: "button", onClick: function () { return setShowPassword(!showPassword); }, className: "absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground", children: showPassword ? (jsxRuntime.jsx(lucideReact.EyeOff, { className: "w-5 h-5" })) : (jsxRuntime.jsx(lucideReact.Eye, { className: "w-5 h-5" })) })] }) }), jsxRuntime.jsx(FormMessage, {})] }));
1733
+ } }), jsxRuntime.jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsx(GenericOTPVerifier, { value: MFACode, setValue: setMFACode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "w-4 h-4 animate-spin" }), jsxRuntime.jsx("span", { children: "Verifying..." })] }))] }))] }) }));
1729
1734
  };
1730
1735
 
1731
1736
  var DefaultLoginPage = function (_a) {
@@ -1750,6 +1755,12 @@ var DefaultLoginPage = function (_a) {
1750
1755
  console.log(data);
1751
1756
  if (state && data && data.isValid) {
1752
1757
  context.isAuthenticated = true;
1758
+ localStorage.setItem(context.storageKey, JSON.stringify({
1759
+ isAuthenticated: false,
1760
+ requiresMFA: false,
1761
+ accessToken: "Credentials",
1762
+ idToken: "Credentials",
1763
+ }));
1753
1764
  context.requiresMFA = false;
1754
1765
  context.setUserProfile({
1755
1766
  state: "AUTH_SUCCESS",
@@ -1765,7 +1776,7 @@ var DefaultLoginPage = function (_a) {
1765
1776
  });
1766
1777
  }
1767
1778
  else {
1768
- sonner.toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || 'Unknown error'));
1779
+ sonner.toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
1769
1780
  }
1770
1781
  return [2 /*return*/];
1771
1782
  });
@@ -1797,7 +1808,12 @@ var DefaultLoginPage = function (_a) {
1797
1808
  return __generator$1(this, function (_c) {
1798
1809
  // Implement your AD login logic here
1799
1810
  console.log("AD Login:", { username: username, MFACode: MFACode });
1800
- handleSubmitCredentials(CredentialsAuthEndpoint, { username: username, password: password, MFACode: MFACode, appCode: context.appCode });
1811
+ handleSubmitCredentials(CredentialsAuthEndpoint, {
1812
+ username: username,
1813
+ password: password,
1814
+ MFACode: MFACode,
1815
+ appCode: context.appCode,
1816
+ });
1801
1817
  return [2 /*return*/];
1802
1818
  });
1803
1819
  }); } })] }));
@@ -1823,7 +1839,7 @@ var MFAGate = function (_a) {
1823
1839
  usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA, onAuthSuccess = _a.onAuthSuccess, onAuthError = _a.onAuthError;
1824
1840
  var context = useCAMSContext();
1825
1841
  var _e = React.useState("Loading"), authState = _e[0], setAuthState = _e[1];
1826
- var validatedMFAEndpoints = React.useMemo(function () {
1842
+ var ValidatedMFAEndpoints = React.useMemo(function () {
1827
1843
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
1828
1844
  if (!parsed.success) {
1829
1845
  camsSdk.Logger.error("Invalid MFAEndpoint", parsed.error);
@@ -1881,20 +1897,19 @@ var MFAGate = function (_a) {
1881
1897
  setAuthState("Loading");
1882
1898
  return;
1883
1899
  }
1884
- if (!context.isAuthenticated) {
1900
+ // Check if user has accessToken (MSAL authenticated)
1901
+ if (!contextAccessToken) {
1885
1902
  setAuthState("Unauthenticated");
1886
1903
  return;
1887
1904
  }
1888
- // If authenticated, determine if MFA is required
1905
+ // User has accessToken, determine if MFA is required
1889
1906
  var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
1890
1907
  console.log("MFA decision:", {
1891
1908
  shouldRequireMFA: shouldRequireMFA,
1892
1909
  hasAccessToken: !!contextAccessToken,
1893
- finalState: shouldRequireMFA && contextAccessToken
1894
- ? "MFA_Required"
1895
- : "Authenticated",
1910
+ finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
1896
1911
  });
1897
- if (shouldRequireMFA && contextAccessToken) {
1912
+ if (shouldRequireMFA) {
1898
1913
  setAuthState("MFA_Required");
1899
1914
  }
1900
1915
  else {
@@ -1906,6 +1921,7 @@ var MFAGate = function (_a) {
1906
1921
  contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
1907
1922
  contextAccessToken, // And this when accessToken changes
1908
1923
  requiresMFA,
1924
+ context.authMode,
1909
1925
  ]);
1910
1926
  // Debug useEffect
1911
1927
  React.useEffect(function () {
@@ -1926,7 +1942,7 @@ var MFAGate = function (_a) {
1926
1942
  ]);
1927
1943
  if (useADLogin && !CredentialsAuthEndpoint)
1928
1944
  return jsxRuntime.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
1929
- if (!validatedMFAEndpoints)
1945
+ if (!ValidatedMFAEndpoints)
1930
1946
  return jsxRuntime.jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
1931
1947
  if (context.authMode !== "MSAL")
1932
1948
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
@@ -1934,12 +1950,12 @@ var MFAGate = function (_a) {
1934
1950
  case "Loading":
1935
1951
  return fallback;
1936
1952
  case "MFA_Required":
1937
- return (jsxRuntime.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
1953
+ return (jsxRuntime.jsx(MFAOptions, { MFAEndpoints: ValidatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
1938
1954
  case "Authenticated":
1939
1955
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
1940
1956
  case "Unauthenticated":
1941
1957
  default:
1942
- return (jsxRuntime.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: MFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
1958
+ return (jsxRuntime.jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: ValidatedMFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
1943
1959
  }
1944
1960
  };
1945
1961