@insforge/react 0.3.1 → 0.3.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/README.md +604 -604
- package/dist/atoms.d.mts +5 -5
- package/dist/atoms.d.ts +5 -5
- package/dist/atoms.js +4 -12
- package/dist/atoms.js.map +1 -1
- package/dist/atoms.mjs +4 -12
- package/dist/atoms.mjs.map +1 -1
- package/dist/components.js +75 -56
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +75 -56
- package/dist/components.mjs.map +1 -1
- package/dist/forms.d.mts +4 -4
- package/dist/forms.d.ts +4 -4
- package/dist/forms.js +33 -21
- package/dist/forms.js.map +1 -1
- package/dist/forms.mjs +33 -21
- package/dist/forms.mjs.map +1 -1
- package/dist/hooks.d.mts +4 -4
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +4 -4
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +4 -4
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +78 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -59
- package/dist/index.mjs.map +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.mjs.map +1 -1
- package/dist/router.js.map +1 -1
- package/dist/router.mjs.map +1 -1
- package/dist/types.d.mts +7 -4
- package/dist/types.d.ts +7 -4
- package/package.json +98 -98
- package/src/styles.css +15 -15
package/dist/index.mjs
CHANGED
|
@@ -252,9 +252,9 @@ function InsforgeProvider({
|
|
|
252
252
|
},
|
|
253
253
|
[user, onAuthChange, insforge]
|
|
254
254
|
);
|
|
255
|
-
const
|
|
255
|
+
const sendResetPasswordEmail = useCallback(
|
|
256
256
|
async (email) => {
|
|
257
|
-
const sdkResult = await insforge.auth.
|
|
257
|
+
const sdkResult = await insforge.auth.sendResetPasswordEmail({ email });
|
|
258
258
|
return sdkResult.data;
|
|
259
259
|
},
|
|
260
260
|
[insforge]
|
|
@@ -290,7 +290,7 @@ function InsforgeProvider({
|
|
|
290
290
|
updateUser,
|
|
291
291
|
reloadAuth: loadAuthState,
|
|
292
292
|
baseUrl,
|
|
293
|
-
|
|
293
|
+
sendResetPasswordEmail,
|
|
294
294
|
resetPassword,
|
|
295
295
|
verifyEmail,
|
|
296
296
|
getPublicAuthConfig
|
|
@@ -308,22 +308,22 @@ function useInsforge() {
|
|
|
308
308
|
}
|
|
309
309
|
function usePublicAuthConfig() {
|
|
310
310
|
const { getPublicAuthConfig } = useInsforge();
|
|
311
|
-
const [
|
|
311
|
+
const [authConfig, setAuthConfig] = useState(null);
|
|
312
312
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
313
313
|
useEffect(() => {
|
|
314
314
|
async function fetchConfig() {
|
|
315
315
|
const result = await getPublicAuthConfig();
|
|
316
316
|
if (result) {
|
|
317
|
-
|
|
317
|
+
setAuthConfig(result);
|
|
318
318
|
} else {
|
|
319
319
|
console.error("[usePublicAuthConfig] Failed to get public auth config");
|
|
320
|
-
|
|
320
|
+
setAuthConfig(null);
|
|
321
321
|
}
|
|
322
322
|
setIsLoaded(true);
|
|
323
323
|
}
|
|
324
324
|
fetchConfig();
|
|
325
325
|
}, [getPublicAuthConfig]);
|
|
326
|
-
return {
|
|
326
|
+
return { authConfig, isLoaded };
|
|
327
327
|
}
|
|
328
328
|
function AuthBranding() {
|
|
329
329
|
return /* @__PURE__ */ jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
|
|
@@ -560,7 +560,7 @@ function AuthPasswordField({
|
|
|
560
560
|
label,
|
|
561
561
|
id,
|
|
562
562
|
showStrengthIndicator = false,
|
|
563
|
-
|
|
563
|
+
authConfig,
|
|
564
564
|
forgotPasswordLink,
|
|
565
565
|
value,
|
|
566
566
|
appearance = {},
|
|
@@ -638,7 +638,7 @@ function AuthPasswordField({
|
|
|
638
638
|
AuthPasswordStrengthIndicator,
|
|
639
639
|
{
|
|
640
640
|
password: String(value || ""),
|
|
641
|
-
config:
|
|
641
|
+
config: authConfig
|
|
642
642
|
}
|
|
643
643
|
)
|
|
644
644
|
]
|
|
@@ -1075,11 +1075,7 @@ function AuthEmailVerificationStep({
|
|
|
1075
1075
|
useEffect(() => {
|
|
1076
1076
|
const sendInitialEmail = async () => {
|
|
1077
1077
|
try {
|
|
1078
|
-
|
|
1079
|
-
await insforge.auth.sendVerificationCode({ email });
|
|
1080
|
-
} else {
|
|
1081
|
-
await insforge.auth.sendVerificationLink({ email });
|
|
1082
|
-
}
|
|
1078
|
+
await insforge.auth.sendVerificationEmail({ email });
|
|
1083
1079
|
} catch {
|
|
1084
1080
|
}
|
|
1085
1081
|
};
|
|
@@ -1105,11 +1101,7 @@ function AuthEmailVerificationStep({
|
|
|
1105
1101
|
setIsSending(true);
|
|
1106
1102
|
setVerificationError("");
|
|
1107
1103
|
try {
|
|
1108
|
-
|
|
1109
|
-
await insforge.auth.sendVerificationCode({ email });
|
|
1110
|
-
} else {
|
|
1111
|
-
await insforge.auth.sendVerificationLink({ email });
|
|
1112
|
-
}
|
|
1104
|
+
await insforge.auth.sendVerificationEmail({ email });
|
|
1113
1105
|
} catch {
|
|
1114
1106
|
setResendDisabled(false);
|
|
1115
1107
|
setResendCountdown(0);
|
|
@@ -1187,7 +1179,7 @@ function SignInForm({
|
|
|
1187
1179
|
oauthLoading = null,
|
|
1188
1180
|
availableProviders = [],
|
|
1189
1181
|
onOAuthClick,
|
|
1190
|
-
|
|
1182
|
+
authConfig,
|
|
1191
1183
|
appearance = {},
|
|
1192
1184
|
title = "Welcome Back",
|
|
1193
1185
|
subtitle = "Login to your account",
|
|
@@ -1277,7 +1269,7 @@ function SignInForm({
|
|
|
1277
1269
|
onChange: (e) => onPasswordChange(e.target.value),
|
|
1278
1270
|
required: true,
|
|
1279
1271
|
autoComplete: "current-password",
|
|
1280
|
-
|
|
1272
|
+
authConfig,
|
|
1281
1273
|
forgotPasswordLink: forgotPasswordUrl ? {
|
|
1282
1274
|
href: forgotPasswordUrl,
|
|
1283
1275
|
text: forgotPasswordText
|
|
@@ -1348,7 +1340,7 @@ function SignIn({
|
|
|
1348
1340
|
...uiProps
|
|
1349
1341
|
}) {
|
|
1350
1342
|
const { signIn, baseUrl } = useInsforge();
|
|
1351
|
-
const {
|
|
1343
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1352
1344
|
const [email, setEmail] = useState("");
|
|
1353
1345
|
const [password, setPassword] = useState("");
|
|
1354
1346
|
const [error, setError] = useState("");
|
|
@@ -1414,7 +1406,7 @@ function SignIn({
|
|
|
1414
1406
|
setOauthLoading(null);
|
|
1415
1407
|
}
|
|
1416
1408
|
}
|
|
1417
|
-
if (!
|
|
1409
|
+
if (!authConfig) {
|
|
1418
1410
|
return null;
|
|
1419
1411
|
}
|
|
1420
1412
|
return /* @__PURE__ */ jsx(
|
|
@@ -1428,9 +1420,9 @@ function SignIn({
|
|
|
1428
1420
|
error,
|
|
1429
1421
|
loading,
|
|
1430
1422
|
oauthLoading,
|
|
1431
|
-
availableProviders:
|
|
1423
|
+
availableProviders: authConfig?.oAuthProviders || [],
|
|
1432
1424
|
onOAuthClick: handleOAuth,
|
|
1433
|
-
|
|
1425
|
+
authConfig,
|
|
1434
1426
|
showVerificationStep: step === "awaiting-verification",
|
|
1435
1427
|
onVerifyCode: handleVerifyCode,
|
|
1436
1428
|
...uiProps
|
|
@@ -1448,7 +1440,7 @@ function SignUpForm({
|
|
|
1448
1440
|
oauthLoading = null,
|
|
1449
1441
|
availableProviders = [],
|
|
1450
1442
|
onOAuthClick,
|
|
1451
|
-
|
|
1443
|
+
authConfig,
|
|
1452
1444
|
appearance = {},
|
|
1453
1445
|
title = "Get Started",
|
|
1454
1446
|
subtitle = "Create your account",
|
|
@@ -1535,10 +1527,10 @@ function SignUpForm({
|
|
|
1535
1527
|
value: password,
|
|
1536
1528
|
onChange: (e) => onPasswordChange(e.target.value),
|
|
1537
1529
|
required: true,
|
|
1538
|
-
minLength:
|
|
1530
|
+
minLength: authConfig.passwordMinLength,
|
|
1539
1531
|
autoComplete: "new-password",
|
|
1540
1532
|
showStrengthIndicator: true,
|
|
1541
|
-
|
|
1533
|
+
authConfig,
|
|
1542
1534
|
appearance: {
|
|
1543
1535
|
containerClassName: appearance.form?.passwordField?.container,
|
|
1544
1536
|
labelClassName: appearance.form?.passwordField?.label,
|
|
@@ -1676,7 +1668,7 @@ function SignUp({
|
|
|
1676
1668
|
...uiProps
|
|
1677
1669
|
}) {
|
|
1678
1670
|
const { signUp, baseUrl } = useInsforge();
|
|
1679
|
-
const {
|
|
1671
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1680
1672
|
const [email, setEmail] = useState("");
|
|
1681
1673
|
const [password, setPassword] = useState("");
|
|
1682
1674
|
const [error, setError] = useState("");
|
|
@@ -1690,7 +1682,7 @@ function SignUp({
|
|
|
1690
1682
|
e.preventDefault();
|
|
1691
1683
|
setLoading(true);
|
|
1692
1684
|
setError("");
|
|
1693
|
-
if (!
|
|
1685
|
+
if (!authConfig) {
|
|
1694
1686
|
setError("Configuration not loaded. Please refresh the page.");
|
|
1695
1687
|
setLoading(false);
|
|
1696
1688
|
return;
|
|
@@ -1703,11 +1695,11 @@ function SignUp({
|
|
|
1703
1695
|
return;
|
|
1704
1696
|
}
|
|
1705
1697
|
const passwordZodSchema = createPasswordSchema({
|
|
1706
|
-
minLength:
|
|
1707
|
-
requireUppercase:
|
|
1708
|
-
requireLowercase:
|
|
1709
|
-
requireNumber:
|
|
1710
|
-
requireSpecialChar:
|
|
1698
|
+
minLength: authConfig.passwordMinLength,
|
|
1699
|
+
requireUppercase: authConfig.requireUppercase,
|
|
1700
|
+
requireLowercase: authConfig.requireLowercase,
|
|
1701
|
+
requireNumber: authConfig.requireNumber,
|
|
1702
|
+
requireSpecialChar: authConfig.requireSpecialChar
|
|
1711
1703
|
});
|
|
1712
1704
|
const passwordValidation = passwordZodSchema.safeParse(password);
|
|
1713
1705
|
if (!passwordValidation.success) {
|
|
@@ -1769,7 +1761,7 @@ function SignUp({
|
|
|
1769
1761
|
setOauthLoading(null);
|
|
1770
1762
|
}
|
|
1771
1763
|
}
|
|
1772
|
-
if (!
|
|
1764
|
+
if (!authConfig) {
|
|
1773
1765
|
return null;
|
|
1774
1766
|
}
|
|
1775
1767
|
return /* @__PURE__ */ jsx(
|
|
@@ -1783,9 +1775,9 @@ function SignUp({
|
|
|
1783
1775
|
error,
|
|
1784
1776
|
loading,
|
|
1785
1777
|
oauthLoading,
|
|
1786
|
-
availableProviders:
|
|
1778
|
+
availableProviders: authConfig?.oAuthProviders || [],
|
|
1787
1779
|
onOAuthClick: handleOAuth,
|
|
1788
|
-
|
|
1780
|
+
authConfig,
|
|
1789
1781
|
showVerificationStep: step === "awaiting-verification",
|
|
1790
1782
|
onVerifyCode: handleVerifyCode,
|
|
1791
1783
|
...uiProps
|
|
@@ -1916,7 +1908,8 @@ function ResetPasswordForm({
|
|
|
1916
1908
|
onSubmit,
|
|
1917
1909
|
error,
|
|
1918
1910
|
loading = false,
|
|
1919
|
-
|
|
1911
|
+
success = false,
|
|
1912
|
+
authConfig,
|
|
1920
1913
|
appearance = {},
|
|
1921
1914
|
title = "Reset Password",
|
|
1922
1915
|
subtitle = "Enter your new password below.",
|
|
@@ -1927,8 +1920,27 @@ function ResetPasswordForm({
|
|
|
1927
1920
|
submitButtonText = "Reset Password",
|
|
1928
1921
|
loadingButtonText = "Resetting...",
|
|
1929
1922
|
backToSignInText = "",
|
|
1930
|
-
backToSignInUrl = "/sign-in"
|
|
1923
|
+
backToSignInUrl = "/sign-in",
|
|
1924
|
+
successTitle = "Password Reset Successful!",
|
|
1925
|
+
successMessage = "Your password has been successfully reset. You can now sign in with your new password."
|
|
1931
1926
|
}) {
|
|
1927
|
+
if (success) {
|
|
1928
|
+
return /* @__PURE__ */ jsx(
|
|
1929
|
+
AuthContainer,
|
|
1930
|
+
{
|
|
1931
|
+
appearance: {
|
|
1932
|
+
containerClassName: appearance.container,
|
|
1933
|
+
cardClassName: appearance.card
|
|
1934
|
+
},
|
|
1935
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-4", children: [
|
|
1936
|
+
/* @__PURE__ */ jsx("div", { className: "w-16 h-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center", children: /* @__PURE__ */ jsx("svg", { className: "w-8 h-8 text-green-600 dark:text-green-400", fill: "none", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M5 13l4 4L19 7" }) }) }),
|
|
1937
|
+
/* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold text-black dark:text-white text-center", children: successTitle }),
|
|
1938
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 text-center", children: successMessage }),
|
|
1939
|
+
/* @__PURE__ */ jsx("a", { href: backToSignInUrl, className: "mt-4 text-black dark:text-white font-medium", children: "Back to Sign In" })
|
|
1940
|
+
] })
|
|
1941
|
+
}
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1932
1944
|
return /* @__PURE__ */ jsxs(
|
|
1933
1945
|
AuthContainer,
|
|
1934
1946
|
{
|
|
@@ -1974,7 +1986,7 @@ function ResetPasswordForm({
|
|
|
1974
1986
|
required: true,
|
|
1975
1987
|
autoComplete: "new-password",
|
|
1976
1988
|
showStrengthIndicator: true,
|
|
1977
|
-
|
|
1989
|
+
authConfig,
|
|
1978
1990
|
appearance: {
|
|
1979
1991
|
containerClassName: appearance.form?.newPasswordField?.container,
|
|
1980
1992
|
labelClassName: appearance.form?.newPasswordField?.label,
|
|
@@ -1992,7 +2004,7 @@ function ResetPasswordForm({
|
|
|
1992
2004
|
onChange: (e) => onConfirmPasswordChange(e.target.value),
|
|
1993
2005
|
required: true,
|
|
1994
2006
|
autoComplete: "new-password",
|
|
1995
|
-
|
|
2007
|
+
authConfig,
|
|
1996
2008
|
appearance: {
|
|
1997
2009
|
containerClassName: appearance.form?.confirmPasswordField?.container,
|
|
1998
2010
|
labelClassName: appearance.form?.confirmPasswordField?.label,
|
|
@@ -2036,16 +2048,17 @@ function ResetPassword({
|
|
|
2036
2048
|
...uiProps
|
|
2037
2049
|
}) {
|
|
2038
2050
|
const { resetPassword } = useInsforge();
|
|
2039
|
-
const {
|
|
2051
|
+
const { authConfig } = usePublicAuthConfig();
|
|
2040
2052
|
const [newPassword, setNewPassword] = useState("");
|
|
2041
2053
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
2042
2054
|
const [error, setError] = useState("");
|
|
2043
2055
|
const [loading, setLoading] = useState(false);
|
|
2056
|
+
const [success, setSuccess] = useState(false);
|
|
2044
2057
|
async function handleSubmit(e) {
|
|
2045
2058
|
e.preventDefault();
|
|
2046
2059
|
setLoading(true);
|
|
2047
2060
|
setError("");
|
|
2048
|
-
if (!
|
|
2061
|
+
if (!authConfig) {
|
|
2049
2062
|
setError("Configuration not loaded. Please refresh the page.");
|
|
2050
2063
|
setLoading(false);
|
|
2051
2064
|
return;
|
|
@@ -2061,11 +2074,11 @@ function ResetPassword({
|
|
|
2061
2074
|
return;
|
|
2062
2075
|
}
|
|
2063
2076
|
const passwordZodSchema = createPasswordSchema({
|
|
2064
|
-
minLength:
|
|
2065
|
-
requireUppercase:
|
|
2066
|
-
requireLowercase:
|
|
2067
|
-
requireNumber:
|
|
2068
|
-
requireSpecialChar:
|
|
2077
|
+
minLength: authConfig.passwordMinLength,
|
|
2078
|
+
requireUppercase: authConfig.requireUppercase,
|
|
2079
|
+
requireLowercase: authConfig.requireLowercase,
|
|
2080
|
+
requireNumber: authConfig.requireNumber,
|
|
2081
|
+
requireSpecialChar: authConfig.requireSpecialChar
|
|
2069
2082
|
});
|
|
2070
2083
|
const passwordValidation = passwordZodSchema.safeParse(newPassword);
|
|
2071
2084
|
if (!passwordValidation.success) {
|
|
@@ -2077,6 +2090,7 @@ function ResetPassword({
|
|
|
2077
2090
|
try {
|
|
2078
2091
|
const result = await resetPassword(token, newPassword);
|
|
2079
2092
|
if (result?.message) {
|
|
2093
|
+
setSuccess(true);
|
|
2080
2094
|
if (onSuccess) {
|
|
2081
2095
|
onSuccess(result.redirectTo);
|
|
2082
2096
|
}
|
|
@@ -2097,7 +2111,7 @@ function ResetPassword({
|
|
|
2097
2111
|
setLoading(false);
|
|
2098
2112
|
}
|
|
2099
2113
|
}
|
|
2100
|
-
if (!
|
|
2114
|
+
if (!authConfig) {
|
|
2101
2115
|
return null;
|
|
2102
2116
|
}
|
|
2103
2117
|
return /* @__PURE__ */ jsx(
|
|
@@ -2110,7 +2124,8 @@ function ResetPassword({
|
|
|
2110
2124
|
onSubmit: handleSubmit,
|
|
2111
2125
|
error,
|
|
2112
2126
|
loading,
|
|
2113
|
-
|
|
2127
|
+
success,
|
|
2128
|
+
authConfig,
|
|
2114
2129
|
backToSignInUrl,
|
|
2115
2130
|
...uiProps
|
|
2116
2131
|
}
|
|
@@ -2122,8 +2137,8 @@ function ForgotPassword({
|
|
|
2122
2137
|
onError,
|
|
2123
2138
|
...uiProps
|
|
2124
2139
|
}) {
|
|
2125
|
-
const {
|
|
2126
|
-
const {
|
|
2140
|
+
const { sendResetPasswordEmail, baseUrl } = useInsforge();
|
|
2141
|
+
const { authConfig } = usePublicAuthConfig();
|
|
2127
2142
|
const [insforge] = useState(() => createClient({ baseUrl }));
|
|
2128
2143
|
const [step, setStep] = useState("email");
|
|
2129
2144
|
const [email, setEmail] = useState("");
|
|
@@ -2162,9 +2177,9 @@ function ForgotPassword({
|
|
|
2162
2177
|
return;
|
|
2163
2178
|
}
|
|
2164
2179
|
try {
|
|
2165
|
-
const result = await
|
|
2180
|
+
const result = await sendResetPasswordEmail(emailValidation.data);
|
|
2166
2181
|
if (result?.success) {
|
|
2167
|
-
if (
|
|
2182
|
+
if (authConfig?.resetPasswordMethod === "link") {
|
|
2168
2183
|
setSuccess(true);
|
|
2169
2184
|
if (onSuccess) {
|
|
2170
2185
|
onSuccess();
|
|
@@ -2217,7 +2232,7 @@ function ForgotPassword({
|
|
|
2217
2232
|
setIsSendingCode(true);
|
|
2218
2233
|
setError("");
|
|
2219
2234
|
try {
|
|
2220
|
-
await
|
|
2235
|
+
await sendResetPasswordEmail(email);
|
|
2221
2236
|
} catch (err) {
|
|
2222
2237
|
setError(err.message || "Failed to resend code");
|
|
2223
2238
|
setResendDisabled(false);
|
|
@@ -2225,13 +2240,17 @@ function ForgotPassword({
|
|
|
2225
2240
|
} finally {
|
|
2226
2241
|
setIsSendingCode(false);
|
|
2227
2242
|
}
|
|
2228
|
-
}, [email,
|
|
2229
|
-
function handlePasswordResetSuccess() {
|
|
2243
|
+
}, [email, sendResetPasswordEmail]);
|
|
2244
|
+
function handlePasswordResetSuccess(redirectTo) {
|
|
2245
|
+
const targetUrl = redirectTo || backToSignInUrl;
|
|
2230
2246
|
if (onSuccess) {
|
|
2231
2247
|
onSuccess();
|
|
2232
2248
|
}
|
|
2249
|
+
setTimeout(() => {
|
|
2250
|
+
window.location.href = targetUrl;
|
|
2251
|
+
}, 1500);
|
|
2233
2252
|
}
|
|
2234
|
-
if (!
|
|
2253
|
+
if (!authConfig) {
|
|
2235
2254
|
return null;
|
|
2236
2255
|
}
|
|
2237
2256
|
if (step === "email") {
|