@nibssplc/cams-sdk-react 1.0.0-rc.81 → 1.0.0-rc.83
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/components/ADLoginModal.d.ts +1 -1
- package/dist/index.cjs.js +74 -58
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +75 -59
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -8,7 +8,7 @@ import { toast } from 'sonner';
|
|
|
8
8
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
9
9
|
import z$1, { z } from 'zod';
|
|
10
10
|
import { OTPInput, OTPInputContext, REGEXP_ONLY_DIGITS } from 'input-otp';
|
|
11
|
-
import { RectangleEllipsis, XIcon, CheckCircle, Shield, KeyIcon, ShieldCheck, ShieldClose, Loader2 } from 'lucide-react';
|
|
11
|
+
import { RectangleEllipsis, XIcon, CheckCircle, Shield, KeyIcon, ShieldCheck, ShieldClose, EyeOff, Eye, Loader2 } from 'lucide-react';
|
|
12
12
|
import { appendErrors, FormProvider, Controller, useFormContext, useFormState, useForm } from 'react-hook-form';
|
|
13
13
|
import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
|
|
14
14
|
import { clsx } from 'clsx';
|
|
@@ -420,11 +420,9 @@ function useCAMSMSALAuth(options) {
|
|
|
420
420
|
var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
421
421
|
var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
|
|
422
422
|
var _f = useState(""), email = _f[0], setEmail = _f[1];
|
|
423
|
-
// const [mfaAuthenticator, setMfaAuthenticator] =
|
|
424
|
-
// useState<CAMSMFAAuthenticator | null>(null);
|
|
425
423
|
var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
|
|
426
424
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
427
|
-
var isAuthenticated = !!account && !!accessToken
|
|
425
|
+
var isAuthenticated = !!account && !!accessToken;
|
|
428
426
|
var scopes = optScopes || ["openid", "profile", "email"];
|
|
429
427
|
var isTokenValid = function (token) {
|
|
430
428
|
try {
|
|
@@ -1642,12 +1640,13 @@ var credentialsSchema = z.object({
|
|
|
1642
1640
|
});
|
|
1643
1641
|
var ADLoginModal = function (_a) {
|
|
1644
1642
|
var open = _a.open, isLoading = _a.isLoading, setIsLoading = _a.setIsLoading, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
1645
|
-
var _b = useState("
|
|
1646
|
-
var _c = useState(
|
|
1643
|
+
var _b = useState("Credentials"), step = _b[0], setStep = _b[1];
|
|
1644
|
+
var _c = useState(false), showPassword = _c[0], setShowPassword = _c[1];
|
|
1645
|
+
var _d = useState({
|
|
1647
1646
|
username: "",
|
|
1648
1647
|
password: "",
|
|
1649
|
-
}), credentials =
|
|
1650
|
-
var
|
|
1648
|
+
}), credentials = _d[0], setCredentials = _d[1];
|
|
1649
|
+
var _e = useState(""), MFACode = _e[0], setMFACode = _e[1];
|
|
1651
1650
|
var form = useForm({
|
|
1652
1651
|
resolver: a$1(credentialsSchema),
|
|
1653
1652
|
defaultValues: { username: "", password: "" },
|
|
@@ -1655,7 +1654,7 @@ var ADLoginModal = function (_a) {
|
|
|
1655
1654
|
var handleCredentialsSubmit = function (values) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1656
1655
|
return __generator$1(this, function (_a) {
|
|
1657
1656
|
setCredentials(values);
|
|
1658
|
-
setStep("
|
|
1657
|
+
setStep("MFA");
|
|
1659
1658
|
return [2 /*return*/];
|
|
1660
1659
|
});
|
|
1661
1660
|
}); };
|
|
@@ -1677,9 +1676,9 @@ var ADLoginModal = function (_a) {
|
|
|
1677
1676
|
case 2:
|
|
1678
1677
|
_a.sent();
|
|
1679
1678
|
onOpenChange(false);
|
|
1680
|
-
setStep("
|
|
1679
|
+
setStep("Credentials");
|
|
1681
1680
|
form.reset();
|
|
1682
|
-
|
|
1681
|
+
setMFACode("");
|
|
1683
1682
|
return [3 /*break*/, 5];
|
|
1684
1683
|
case 3:
|
|
1685
1684
|
error_1 = _a.sent();
|
|
@@ -1694,17 +1693,18 @@ var ADLoginModal = function (_a) {
|
|
|
1694
1693
|
}); };
|
|
1695
1694
|
var handleClose = function () {
|
|
1696
1695
|
onOpenChange(false);
|
|
1697
|
-
setStep("
|
|
1696
|
+
setStep("Credentials");
|
|
1698
1697
|
form.reset();
|
|
1699
|
-
|
|
1698
|
+
setMFACode("");
|
|
1699
|
+
setShowPassword(false);
|
|
1700
1700
|
};
|
|
1701
|
-
return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-4", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "
|
|
1701
|
+
return (jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxs(DialogContent, { className: "min-w-[50vw] max-w-[70vw]", children: [jsx(DialogHeader, { children: jsxs("div", { className: "flex items-center gap-4", children: [jsx(KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsx(DialogTitle, { className: "text-xl", children: "Sign in with AD Credentials" })] }) }), step === "Credentials" ? (jsx(Form, __assign({}, form, { children: jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-6", children: [jsx(FormField, { control: form.control, name: "username", render: function (_a) {
|
|
1702
1702
|
var field = _a.field;
|
|
1703
1703
|
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Username" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", placeholder: "Enter your username" }, field)) }), jsx(FormMessage, {})] }));
|
|
1704
1704
|
} }), jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
1705
1705
|
var field = _a.field;
|
|
1706
|
-
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Password" }), jsx(FormControl, { children: jsx(Input, __assign({ className: "h-12", type: "password", placeholder: "Enter your password" }, field)) }), jsx(FormMessage, {})] }));
|
|
1707
|
-
} }), jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value:
|
|
1706
|
+
return (jsxs(FormItem, { children: [jsx(FormLabel, { children: "Password" }), jsx(FormControl, { children: jsxs("div", { className: "relative", children: [jsx(Input, __assign({ className: "h-12 pr-10", type: "password", placeholder: "Enter your password" }, field)), 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 ? (jsx(EyeOff, { className: "w-5 h-5" })) : (jsx(Eye, { className: "w-5 h-5" })) })] }) }), jsx(FormMessage, {})] }));
|
|
1707
|
+
} }), jsx(Button, { type: "submit", className: "py-3 w-full bg-[#506f4a] hover:bg-[#506f4a]/90", children: "Continue" })] }) }))) : (jsxs("div", { className: "space-y-4", children: [jsx(GenericOTPVerifier, { value: MFACode, setValue: setMFACode, setLoading: setIsLoading, isDisabled: isLoading, onChangeOTP: handleMFASubmit, fieldName: "AuthenticatorCode" }), isLoading && (jsxs("div", { className: "flex items-center justify-center gap-2 text-sm text-muted-foreground", children: [jsx(Loader2, { className: "w-4 h-4 animate-spin" }), jsx("span", { children: "Verifying..." })] }))] }))] }) }));
|
|
1708
1708
|
};
|
|
1709
1709
|
|
|
1710
1710
|
var DefaultLoginPage = function (_a) {
|
|
@@ -1729,6 +1729,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1729
1729
|
console.log(data);
|
|
1730
1730
|
if (state && data && data.isValid) {
|
|
1731
1731
|
context.isAuthenticated = true;
|
|
1732
|
+
localStorage.setItem(context.storageKey, JSON.stringify({
|
|
1733
|
+
isAuthenticated: false,
|
|
1734
|
+
requiresMFA: false,
|
|
1735
|
+
accessToken: "Credentials",
|
|
1736
|
+
idToken: "Credentials",
|
|
1737
|
+
}));
|
|
1732
1738
|
context.requiresMFA = false;
|
|
1733
1739
|
context.setUserProfile({
|
|
1734
1740
|
state: "AUTH_SUCCESS",
|
|
@@ -1744,7 +1750,7 @@ var DefaultLoginPage = function (_a) {
|
|
|
1744
1750
|
});
|
|
1745
1751
|
}
|
|
1746
1752
|
else {
|
|
1747
|
-
toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) ||
|
|
1753
|
+
toast.error("\u274C AD Login failed. ".concat((data === null || data === void 0 ? void 0 : data.message) || "Unknown error"));
|
|
1748
1754
|
}
|
|
1749
1755
|
return [2 /*return*/];
|
|
1750
1756
|
});
|
|
@@ -1776,7 +1782,12 @@ var DefaultLoginPage = function (_a) {
|
|
|
1776
1782
|
return __generator$1(this, function (_c) {
|
|
1777
1783
|
// Implement your AD login logic here
|
|
1778
1784
|
console.log("AD Login:", { username: username, MFACode: MFACode });
|
|
1779
|
-
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1785
|
+
handleSubmitCredentials(CredentialsAuthEndpoint, {
|
|
1786
|
+
username: username,
|
|
1787
|
+
password: password,
|
|
1788
|
+
MFACode: MFACode,
|
|
1789
|
+
appCode: context.appCode,
|
|
1790
|
+
});
|
|
1780
1791
|
return [2 /*return*/];
|
|
1781
1792
|
});
|
|
1782
1793
|
}); } })] }));
|
|
@@ -1795,15 +1806,14 @@ var MFAEndpointsSchema = z$1.object({
|
|
|
1795
1806
|
AuthChallengeVerify: z$1.url("MFA AuthChallengeVerify must be a valid URL"),
|
|
1796
1807
|
});
|
|
1797
1808
|
var MFAGate = function (_a) {
|
|
1798
|
-
var _b,
|
|
1799
|
-
var children = _a.children, _e = _a.fallback, fallback = _e === void 0 ? (jsx("div", { className: "h-screen flex items-center justify-center", children: jsx(LoadingSpinner, {}) })) : _e,
|
|
1809
|
+
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? (jsx("div", { className: "h-screen flex items-center justify-center", children: jsx(LoadingSpinner, {}) })) : _b,
|
|
1800
1810
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1801
|
-
|
|
1811
|
+
_c = _a.usePassKey,
|
|
1802
1812
|
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1803
|
-
usePassKey =
|
|
1813
|
+
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;
|
|
1804
1814
|
var context = useCAMSContext();
|
|
1805
|
-
var
|
|
1806
|
-
var
|
|
1815
|
+
var _e = useState("Loading"), authState = _e[0], setAuthState = _e[1];
|
|
1816
|
+
var ValidatedMFAEndpoints = useMemo(function () {
|
|
1807
1817
|
var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
|
|
1808
1818
|
if (!parsed.success) {
|
|
1809
1819
|
Logger.error("Invalid MFAEndpoint", parsed.error);
|
|
@@ -1811,6 +1821,9 @@ var MFAGate = function (_a) {
|
|
|
1811
1821
|
}
|
|
1812
1822
|
return parsed.data;
|
|
1813
1823
|
}, [MFAEndpoints]);
|
|
1824
|
+
// Extract the specific values we need from context for dependencies
|
|
1825
|
+
var contextRequiresMFA = "requiresMFA" in context ? context.requiresMFA : false;
|
|
1826
|
+
var contextAccessToken = "accessToken" in context ? context.accessToken : "";
|
|
1814
1827
|
var handleComplete = useCallback(function (success) {
|
|
1815
1828
|
var _a;
|
|
1816
1829
|
if (success && context.authMode === "MSAL") {
|
|
@@ -1846,61 +1859,64 @@ var MFAGate = function (_a) {
|
|
|
1846
1859
|
}
|
|
1847
1860
|
});
|
|
1848
1861
|
}); }, [context, onAuthError]);
|
|
1849
|
-
Logger.debug("User context:", {
|
|
1850
|
-
user: context.user,
|
|
1851
|
-
profile: (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile,
|
|
1852
|
-
email: (_d = (_c = context.user) === null || _c === void 0 ? void 0 : _c.profile) === null || _d === void 0 ? void 0 : _d.email,
|
|
1853
|
-
});
|
|
1854
1862
|
useEffect(function () {
|
|
1863
|
+
console.log("Auth evaluation triggered:", {
|
|
1864
|
+
isLoading: context.isLoading,
|
|
1865
|
+
isAuthenticated: context.isAuthenticated,
|
|
1866
|
+
contextRequiresMFA: contextRequiresMFA,
|
|
1867
|
+
contextAccessToken: !!contextAccessToken,
|
|
1868
|
+
requiresMFA: requiresMFA,
|
|
1869
|
+
});
|
|
1855
1870
|
if (context.isLoading) {
|
|
1856
1871
|
setAuthState("Loading");
|
|
1857
1872
|
return;
|
|
1858
1873
|
}
|
|
1859
|
-
if (
|
|
1874
|
+
// Check if user has accessToken (MSAL authenticated)
|
|
1875
|
+
if (!contextAccessToken) {
|
|
1860
1876
|
setAuthState("Unauthenticated");
|
|
1861
1877
|
return;
|
|
1862
1878
|
}
|
|
1863
|
-
//
|
|
1864
|
-
var
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
}
|
|
1877
|
-
else {
|
|
1878
|
-
setAuthState("Authenticated");
|
|
1879
|
-
}
|
|
1880
|
-
}, 50);
|
|
1881
|
-
return function () { return clearTimeout(timer); };
|
|
1879
|
+
// User has accessToken, determine if MFA is required
|
|
1880
|
+
var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : contextRequiresMFA;
|
|
1881
|
+
console.log("MFA decision:", {
|
|
1882
|
+
shouldRequireMFA: shouldRequireMFA,
|
|
1883
|
+
hasAccessToken: !!contextAccessToken,
|
|
1884
|
+
finalState: shouldRequireMFA ? "MFA_Required" : "Authenticated",
|
|
1885
|
+
});
|
|
1886
|
+
if (shouldRequireMFA) {
|
|
1887
|
+
setAuthState("MFA_Required");
|
|
1888
|
+
}
|
|
1889
|
+
else {
|
|
1890
|
+
setAuthState("Authenticated");
|
|
1891
|
+
}
|
|
1882
1892
|
}, [
|
|
1883
|
-
context.accessToken,
|
|
1884
1893
|
context.isLoading,
|
|
1885
1894
|
context.isAuthenticated,
|
|
1886
|
-
|
|
1895
|
+
contextRequiresMFA, // Now this will trigger re-evaluation when requiresMFA changes
|
|
1896
|
+
contextAccessToken, // And this when accessToken changes
|
|
1887
1897
|
requiresMFA,
|
|
1888
|
-
context,
|
|
1898
|
+
context.authMode,
|
|
1889
1899
|
]);
|
|
1890
|
-
//
|
|
1900
|
+
// Debug useEffect
|
|
1891
1901
|
useEffect(function () {
|
|
1892
1902
|
console.log("Current authState:", authState);
|
|
1893
1903
|
console.log("Context state:", {
|
|
1894
1904
|
isLoading: context.isLoading,
|
|
1895
1905
|
isAuthenticated: context.isAuthenticated,
|
|
1896
1906
|
authMode: context.authMode,
|
|
1897
|
-
requiresMFA:
|
|
1898
|
-
hasAccessToken:
|
|
1907
|
+
requiresMFA: contextRequiresMFA,
|
|
1908
|
+
hasAccessToken: !!contextAccessToken,
|
|
1899
1909
|
});
|
|
1900
|
-
}, [
|
|
1910
|
+
}, [
|
|
1911
|
+
authState,
|
|
1912
|
+
context.isLoading,
|
|
1913
|
+
context.isAuthenticated,
|
|
1914
|
+
contextRequiresMFA,
|
|
1915
|
+
contextAccessToken,
|
|
1916
|
+
]);
|
|
1901
1917
|
if (useADLogin && !CredentialsAuthEndpoint)
|
|
1902
1918
|
return jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
|
|
1903
|
-
if (!
|
|
1919
|
+
if (!ValidatedMFAEndpoints)
|
|
1904
1920
|
return jsx(ErrorFallback, { message: "Invalid MFA Configuration." });
|
|
1905
1921
|
if (context.authMode !== "MSAL")
|
|
1906
1922
|
return jsx(Fragment, { children: children });
|
|
@@ -1908,12 +1924,12 @@ var MFAGate = function (_a) {
|
|
|
1908
1924
|
case "Loading":
|
|
1909
1925
|
return fallback;
|
|
1910
1926
|
case "MFA_Required":
|
|
1911
|
-
return (jsx(MFAOptions, { MFAEndpoints:
|
|
1927
|
+
return (jsx(MFAOptions, { MFAEndpoints: ValidatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
1912
1928
|
case "Authenticated":
|
|
1913
1929
|
return jsx(Fragment, { children: children });
|
|
1914
1930
|
case "Unauthenticated":
|
|
1915
1931
|
default:
|
|
1916
|
-
return (jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints:
|
|
1932
|
+
return (jsx(DefaultLoginPage, { usePassKey: usePassKey, useADLogin: useADLogin, MFAEndpoints: ValidatedMFAEndpoints, PassKeysRegisterProps: PassKeysRegisterProps, CredentialsAuthEndpoint: CredentialsAuthEndpoint }));
|
|
1917
1933
|
}
|
|
1918
1934
|
};
|
|
1919
1935
|
|