@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/components.js
CHANGED
|
@@ -20,22 +20,22 @@ function useInsforge() {
|
|
|
20
20
|
}
|
|
21
21
|
function usePublicAuthConfig() {
|
|
22
22
|
const { getPublicAuthConfig } = useInsforge();
|
|
23
|
-
const [
|
|
23
|
+
const [authConfig, setAuthConfig] = react.useState(null);
|
|
24
24
|
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
25
25
|
react.useEffect(() => {
|
|
26
26
|
async function fetchConfig() {
|
|
27
27
|
const result = await getPublicAuthConfig();
|
|
28
28
|
if (result) {
|
|
29
|
-
|
|
29
|
+
setAuthConfig(result);
|
|
30
30
|
} else {
|
|
31
31
|
console.error("[usePublicAuthConfig] Failed to get public auth config");
|
|
32
|
-
|
|
32
|
+
setAuthConfig(null);
|
|
33
33
|
}
|
|
34
34
|
setIsLoaded(true);
|
|
35
35
|
}
|
|
36
36
|
fetchConfig();
|
|
37
37
|
}, [getPublicAuthConfig]);
|
|
38
|
-
return {
|
|
38
|
+
return { authConfig, isLoaded };
|
|
39
39
|
}
|
|
40
40
|
function AuthBranding() {
|
|
41
41
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
|
|
@@ -272,7 +272,7 @@ function AuthPasswordField({
|
|
|
272
272
|
label,
|
|
273
273
|
id,
|
|
274
274
|
showStrengthIndicator = false,
|
|
275
|
-
|
|
275
|
+
authConfig,
|
|
276
276
|
forgotPasswordLink,
|
|
277
277
|
value,
|
|
278
278
|
appearance = {},
|
|
@@ -350,7 +350,7 @@ function AuthPasswordField({
|
|
|
350
350
|
AuthPasswordStrengthIndicator,
|
|
351
351
|
{
|
|
352
352
|
password: String(value || ""),
|
|
353
|
-
config:
|
|
353
|
+
config: authConfig
|
|
354
354
|
}
|
|
355
355
|
)
|
|
356
356
|
]
|
|
@@ -784,11 +784,7 @@ function AuthEmailVerificationStep({
|
|
|
784
784
|
react.useEffect(() => {
|
|
785
785
|
const sendInitialEmail = async () => {
|
|
786
786
|
try {
|
|
787
|
-
|
|
788
|
-
await insforge.auth.sendVerificationCode({ email });
|
|
789
|
-
} else {
|
|
790
|
-
await insforge.auth.sendVerificationLink({ email });
|
|
791
|
-
}
|
|
787
|
+
await insforge.auth.sendVerificationEmail({ email });
|
|
792
788
|
} catch {
|
|
793
789
|
}
|
|
794
790
|
};
|
|
@@ -814,11 +810,7 @@ function AuthEmailVerificationStep({
|
|
|
814
810
|
setIsSending(true);
|
|
815
811
|
setVerificationError("");
|
|
816
812
|
try {
|
|
817
|
-
|
|
818
|
-
await insforge.auth.sendVerificationCode({ email });
|
|
819
|
-
} else {
|
|
820
|
-
await insforge.auth.sendVerificationLink({ email });
|
|
821
|
-
}
|
|
813
|
+
await insforge.auth.sendVerificationEmail({ email });
|
|
822
814
|
} catch {
|
|
823
815
|
setResendDisabled(false);
|
|
824
816
|
setResendCountdown(0);
|
|
@@ -896,7 +888,7 @@ function SignInForm({
|
|
|
896
888
|
oauthLoading = null,
|
|
897
889
|
availableProviders = [],
|
|
898
890
|
onOAuthClick,
|
|
899
|
-
|
|
891
|
+
authConfig,
|
|
900
892
|
appearance = {},
|
|
901
893
|
title = "Welcome Back",
|
|
902
894
|
subtitle = "Login to your account",
|
|
@@ -986,7 +978,7 @@ function SignInForm({
|
|
|
986
978
|
onChange: (e) => onPasswordChange(e.target.value),
|
|
987
979
|
required: true,
|
|
988
980
|
autoComplete: "current-password",
|
|
989
|
-
|
|
981
|
+
authConfig,
|
|
990
982
|
forgotPasswordLink: forgotPasswordUrl ? {
|
|
991
983
|
href: forgotPasswordUrl,
|
|
992
984
|
text: forgotPasswordText
|
|
@@ -1057,7 +1049,7 @@ function SignIn({
|
|
|
1057
1049
|
...uiProps
|
|
1058
1050
|
}) {
|
|
1059
1051
|
const { signIn, baseUrl } = useInsforge();
|
|
1060
|
-
const {
|
|
1052
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1061
1053
|
const [email, setEmail] = react.useState("");
|
|
1062
1054
|
const [password, setPassword] = react.useState("");
|
|
1063
1055
|
const [error, setError] = react.useState("");
|
|
@@ -1123,7 +1115,7 @@ function SignIn({
|
|
|
1123
1115
|
setOauthLoading(null);
|
|
1124
1116
|
}
|
|
1125
1117
|
}
|
|
1126
|
-
if (!
|
|
1118
|
+
if (!authConfig) {
|
|
1127
1119
|
return null;
|
|
1128
1120
|
}
|
|
1129
1121
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1137,9 +1129,9 @@ function SignIn({
|
|
|
1137
1129
|
error,
|
|
1138
1130
|
loading,
|
|
1139
1131
|
oauthLoading,
|
|
1140
|
-
availableProviders:
|
|
1132
|
+
availableProviders: authConfig?.oAuthProviders || [],
|
|
1141
1133
|
onOAuthClick: handleOAuth,
|
|
1142
|
-
|
|
1134
|
+
authConfig,
|
|
1143
1135
|
showVerificationStep: step === "awaiting-verification",
|
|
1144
1136
|
onVerifyCode: handleVerifyCode,
|
|
1145
1137
|
...uiProps
|
|
@@ -1157,7 +1149,7 @@ function SignUpForm({
|
|
|
1157
1149
|
oauthLoading = null,
|
|
1158
1150
|
availableProviders = [],
|
|
1159
1151
|
onOAuthClick,
|
|
1160
|
-
|
|
1152
|
+
authConfig,
|
|
1161
1153
|
appearance = {},
|
|
1162
1154
|
title = "Get Started",
|
|
1163
1155
|
subtitle = "Create your account",
|
|
@@ -1244,10 +1236,10 @@ function SignUpForm({
|
|
|
1244
1236
|
value: password,
|
|
1245
1237
|
onChange: (e) => onPasswordChange(e.target.value),
|
|
1246
1238
|
required: true,
|
|
1247
|
-
minLength:
|
|
1239
|
+
minLength: authConfig.passwordMinLength,
|
|
1248
1240
|
autoComplete: "new-password",
|
|
1249
1241
|
showStrengthIndicator: true,
|
|
1250
|
-
|
|
1242
|
+
authConfig,
|
|
1251
1243
|
appearance: {
|
|
1252
1244
|
containerClassName: appearance.form?.passwordField?.container,
|
|
1253
1245
|
labelClassName: appearance.form?.passwordField?.label,
|
|
@@ -1342,7 +1334,7 @@ function SignUp({
|
|
|
1342
1334
|
...uiProps
|
|
1343
1335
|
}) {
|
|
1344
1336
|
const { signUp, baseUrl } = useInsforge();
|
|
1345
|
-
const {
|
|
1337
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1346
1338
|
const [email, setEmail] = react.useState("");
|
|
1347
1339
|
const [password, setPassword] = react.useState("");
|
|
1348
1340
|
const [error, setError] = react.useState("");
|
|
@@ -1356,7 +1348,7 @@ function SignUp({
|
|
|
1356
1348
|
e.preventDefault();
|
|
1357
1349
|
setLoading(true);
|
|
1358
1350
|
setError("");
|
|
1359
|
-
if (!
|
|
1351
|
+
if (!authConfig) {
|
|
1360
1352
|
setError("Configuration not loaded. Please refresh the page.");
|
|
1361
1353
|
setLoading(false);
|
|
1362
1354
|
return;
|
|
@@ -1369,11 +1361,11 @@ function SignUp({
|
|
|
1369
1361
|
return;
|
|
1370
1362
|
}
|
|
1371
1363
|
const passwordZodSchema = createPasswordSchema({
|
|
1372
|
-
minLength:
|
|
1373
|
-
requireUppercase:
|
|
1374
|
-
requireLowercase:
|
|
1375
|
-
requireNumber:
|
|
1376
|
-
requireSpecialChar:
|
|
1364
|
+
minLength: authConfig.passwordMinLength,
|
|
1365
|
+
requireUppercase: authConfig.requireUppercase,
|
|
1366
|
+
requireLowercase: authConfig.requireLowercase,
|
|
1367
|
+
requireNumber: authConfig.requireNumber,
|
|
1368
|
+
requireSpecialChar: authConfig.requireSpecialChar
|
|
1377
1369
|
});
|
|
1378
1370
|
const passwordValidation = passwordZodSchema.safeParse(password);
|
|
1379
1371
|
if (!passwordValidation.success) {
|
|
@@ -1435,7 +1427,7 @@ function SignUp({
|
|
|
1435
1427
|
setOauthLoading(null);
|
|
1436
1428
|
}
|
|
1437
1429
|
}
|
|
1438
|
-
if (!
|
|
1430
|
+
if (!authConfig) {
|
|
1439
1431
|
return null;
|
|
1440
1432
|
}
|
|
1441
1433
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1449,9 +1441,9 @@ function SignUp({
|
|
|
1449
1441
|
error,
|
|
1450
1442
|
loading,
|
|
1451
1443
|
oauthLoading,
|
|
1452
|
-
availableProviders:
|
|
1444
|
+
availableProviders: authConfig?.oAuthProviders || [],
|
|
1453
1445
|
onOAuthClick: handleOAuth,
|
|
1454
|
-
|
|
1446
|
+
authConfig,
|
|
1455
1447
|
showVerificationStep: step === "awaiting-verification",
|
|
1456
1448
|
onVerifyCode: handleVerifyCode,
|
|
1457
1449
|
...uiProps
|
|
@@ -1582,7 +1574,8 @@ function ResetPasswordForm({
|
|
|
1582
1574
|
onSubmit,
|
|
1583
1575
|
error,
|
|
1584
1576
|
loading = false,
|
|
1585
|
-
|
|
1577
|
+
success = false,
|
|
1578
|
+
authConfig,
|
|
1586
1579
|
appearance = {},
|
|
1587
1580
|
title = "Reset Password",
|
|
1588
1581
|
subtitle = "Enter your new password below.",
|
|
@@ -1593,8 +1586,27 @@ function ResetPasswordForm({
|
|
|
1593
1586
|
submitButtonText = "Reset Password",
|
|
1594
1587
|
loadingButtonText = "Resetting...",
|
|
1595
1588
|
backToSignInText = "",
|
|
1596
|
-
backToSignInUrl = "/sign-in"
|
|
1589
|
+
backToSignInUrl = "/sign-in",
|
|
1590
|
+
successTitle = "Password Reset Successful!",
|
|
1591
|
+
successMessage = "Your password has been successfully reset. You can now sign in with your new password."
|
|
1597
1592
|
}) {
|
|
1593
|
+
if (success) {
|
|
1594
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1595
|
+
AuthContainer,
|
|
1596
|
+
{
|
|
1597
|
+
appearance: {
|
|
1598
|
+
containerClassName: appearance.container,
|
|
1599
|
+
cardClassName: appearance.card
|
|
1600
|
+
},
|
|
1601
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4", children: [
|
|
1602
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-16 h-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx("path", { d: "M5 13l4 4L19 7" }) }) }),
|
|
1603
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold text-black dark:text-white text-center", children: successTitle }),
|
|
1604
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 text-center", children: successMessage }),
|
|
1605
|
+
/* @__PURE__ */ jsxRuntime.jsx("a", { href: backToSignInUrl, className: "mt-4 text-black dark:text-white font-medium", children: "Back to Sign In" })
|
|
1606
|
+
] })
|
|
1607
|
+
}
|
|
1608
|
+
);
|
|
1609
|
+
}
|
|
1598
1610
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1599
1611
|
AuthContainer,
|
|
1600
1612
|
{
|
|
@@ -1640,7 +1652,7 @@ function ResetPasswordForm({
|
|
|
1640
1652
|
required: true,
|
|
1641
1653
|
autoComplete: "new-password",
|
|
1642
1654
|
showStrengthIndicator: true,
|
|
1643
|
-
|
|
1655
|
+
authConfig,
|
|
1644
1656
|
appearance: {
|
|
1645
1657
|
containerClassName: appearance.form?.newPasswordField?.container,
|
|
1646
1658
|
labelClassName: appearance.form?.newPasswordField?.label,
|
|
@@ -1658,7 +1670,7 @@ function ResetPasswordForm({
|
|
|
1658
1670
|
onChange: (e) => onConfirmPasswordChange(e.target.value),
|
|
1659
1671
|
required: true,
|
|
1660
1672
|
autoComplete: "new-password",
|
|
1661
|
-
|
|
1673
|
+
authConfig,
|
|
1662
1674
|
appearance: {
|
|
1663
1675
|
containerClassName: appearance.form?.confirmPasswordField?.container,
|
|
1664
1676
|
labelClassName: appearance.form?.confirmPasswordField?.label,
|
|
@@ -1702,16 +1714,17 @@ function ResetPassword({
|
|
|
1702
1714
|
...uiProps
|
|
1703
1715
|
}) {
|
|
1704
1716
|
const { resetPassword } = useInsforge();
|
|
1705
|
-
const {
|
|
1717
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1706
1718
|
const [newPassword, setNewPassword] = react.useState("");
|
|
1707
1719
|
const [confirmPassword, setConfirmPassword] = react.useState("");
|
|
1708
1720
|
const [error, setError] = react.useState("");
|
|
1709
1721
|
const [loading, setLoading] = react.useState(false);
|
|
1722
|
+
const [success, setSuccess] = react.useState(false);
|
|
1710
1723
|
async function handleSubmit(e) {
|
|
1711
1724
|
e.preventDefault();
|
|
1712
1725
|
setLoading(true);
|
|
1713
1726
|
setError("");
|
|
1714
|
-
if (!
|
|
1727
|
+
if (!authConfig) {
|
|
1715
1728
|
setError("Configuration not loaded. Please refresh the page.");
|
|
1716
1729
|
setLoading(false);
|
|
1717
1730
|
return;
|
|
@@ -1727,11 +1740,11 @@ function ResetPassword({
|
|
|
1727
1740
|
return;
|
|
1728
1741
|
}
|
|
1729
1742
|
const passwordZodSchema = createPasswordSchema({
|
|
1730
|
-
minLength:
|
|
1731
|
-
requireUppercase:
|
|
1732
|
-
requireLowercase:
|
|
1733
|
-
requireNumber:
|
|
1734
|
-
requireSpecialChar:
|
|
1743
|
+
minLength: authConfig.passwordMinLength,
|
|
1744
|
+
requireUppercase: authConfig.requireUppercase,
|
|
1745
|
+
requireLowercase: authConfig.requireLowercase,
|
|
1746
|
+
requireNumber: authConfig.requireNumber,
|
|
1747
|
+
requireSpecialChar: authConfig.requireSpecialChar
|
|
1735
1748
|
});
|
|
1736
1749
|
const passwordValidation = passwordZodSchema.safeParse(newPassword);
|
|
1737
1750
|
if (!passwordValidation.success) {
|
|
@@ -1743,6 +1756,7 @@ function ResetPassword({
|
|
|
1743
1756
|
try {
|
|
1744
1757
|
const result = await resetPassword(token, newPassword);
|
|
1745
1758
|
if (result?.message) {
|
|
1759
|
+
setSuccess(true);
|
|
1746
1760
|
if (onSuccess) {
|
|
1747
1761
|
onSuccess(result.redirectTo);
|
|
1748
1762
|
}
|
|
@@ -1763,7 +1777,7 @@ function ResetPassword({
|
|
|
1763
1777
|
setLoading(false);
|
|
1764
1778
|
}
|
|
1765
1779
|
}
|
|
1766
|
-
if (!
|
|
1780
|
+
if (!authConfig) {
|
|
1767
1781
|
return null;
|
|
1768
1782
|
}
|
|
1769
1783
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1776,7 +1790,8 @@ function ResetPassword({
|
|
|
1776
1790
|
onSubmit: handleSubmit,
|
|
1777
1791
|
error,
|
|
1778
1792
|
loading,
|
|
1779
|
-
|
|
1793
|
+
success,
|
|
1794
|
+
authConfig,
|
|
1780
1795
|
backToSignInUrl,
|
|
1781
1796
|
...uiProps
|
|
1782
1797
|
}
|
|
@@ -1788,8 +1803,8 @@ function ForgotPassword({
|
|
|
1788
1803
|
onError,
|
|
1789
1804
|
...uiProps
|
|
1790
1805
|
}) {
|
|
1791
|
-
const {
|
|
1792
|
-
const {
|
|
1806
|
+
const { sendResetPasswordEmail, baseUrl } = useInsforge();
|
|
1807
|
+
const { authConfig } = usePublicAuthConfig();
|
|
1793
1808
|
const [insforge] = react.useState(() => sdk.createClient({ baseUrl }));
|
|
1794
1809
|
const [step, setStep] = react.useState("email");
|
|
1795
1810
|
const [email, setEmail] = react.useState("");
|
|
@@ -1828,9 +1843,9 @@ function ForgotPassword({
|
|
|
1828
1843
|
return;
|
|
1829
1844
|
}
|
|
1830
1845
|
try {
|
|
1831
|
-
const result = await
|
|
1846
|
+
const result = await sendResetPasswordEmail(emailValidation.data);
|
|
1832
1847
|
if (result?.success) {
|
|
1833
|
-
if (
|
|
1848
|
+
if (authConfig?.resetPasswordMethod === "link") {
|
|
1834
1849
|
setSuccess(true);
|
|
1835
1850
|
if (onSuccess) {
|
|
1836
1851
|
onSuccess();
|
|
@@ -1883,7 +1898,7 @@ function ForgotPassword({
|
|
|
1883
1898
|
setIsSendingCode(true);
|
|
1884
1899
|
setError("");
|
|
1885
1900
|
try {
|
|
1886
|
-
await
|
|
1901
|
+
await sendResetPasswordEmail(email);
|
|
1887
1902
|
} catch (err) {
|
|
1888
1903
|
setError(err.message || "Failed to resend code");
|
|
1889
1904
|
setResendDisabled(false);
|
|
@@ -1891,13 +1906,17 @@ function ForgotPassword({
|
|
|
1891
1906
|
} finally {
|
|
1892
1907
|
setIsSendingCode(false);
|
|
1893
1908
|
}
|
|
1894
|
-
}, [email,
|
|
1895
|
-
function handlePasswordResetSuccess() {
|
|
1909
|
+
}, [email, sendResetPasswordEmail]);
|
|
1910
|
+
function handlePasswordResetSuccess(redirectTo) {
|
|
1911
|
+
const targetUrl = redirectTo || backToSignInUrl;
|
|
1896
1912
|
if (onSuccess) {
|
|
1897
1913
|
onSuccess();
|
|
1898
1914
|
}
|
|
1915
|
+
setTimeout(() => {
|
|
1916
|
+
window.location.href = targetUrl;
|
|
1917
|
+
}, 1500);
|
|
1899
1918
|
}
|
|
1900
|
-
if (!
|
|
1919
|
+
if (!authConfig) {
|
|
1901
1920
|
return null;
|
|
1902
1921
|
}
|
|
1903
1922
|
if (step === "email") {
|