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