@insforge/react 0.2.2 → 0.2.4
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/atoms.js +17 -1
- package/dist/atoms.js.map +1 -1
- package/dist/atoms.mjs +17 -1
- package/dist/atoms.mjs.map +1 -1
- package/dist/components.js +37 -36
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +37 -36
- package/dist/components.mjs.map +1 -1
- package/dist/forms.js +17 -1
- package/dist/forms.js.map +1 -1
- package/dist/forms.mjs +17 -1
- package/dist/forms.mjs.map +1 -1
- package/dist/hooks.d.mts +5 -3
- package/dist/hooks.d.ts +5 -3
- package/dist/hooks.js +10 -29
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +10 -29
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +60 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -38
- package/dist/index.mjs.map +1 -1
- package/dist/router.js.map +1 -1
- package/dist/router.mjs.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -105,6 +105,23 @@ function InsforgeProvider({
|
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
}, []);
|
|
108
|
+
const getPublicAuthConfig = useCallback(async () => {
|
|
109
|
+
try {
|
|
110
|
+
const result = await insforge.auth.getPublicAuthConfig();
|
|
111
|
+
if (result.data) {
|
|
112
|
+
return result.data;
|
|
113
|
+
} else {
|
|
114
|
+
console.error("[InsforgeProvider] Failed to get public auth config:", result.error);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(
|
|
119
|
+
"[InsforgeProvider] Failed to get public auth config:",
|
|
120
|
+
error
|
|
121
|
+
);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}, [insforge]);
|
|
108
125
|
const handleAuthSuccess = useCallback(
|
|
109
126
|
async (authToken, fallbackUser) => {
|
|
110
127
|
const userResult = await insforge.auth.getCurrentUser();
|
|
@@ -236,7 +253,10 @@ function InsforgeProvider({
|
|
|
236
253
|
);
|
|
237
254
|
const resetPassword = useCallback(
|
|
238
255
|
async (token, newPassword) => {
|
|
239
|
-
const sdkResult = await insforge.auth.resetPassword({
|
|
256
|
+
const sdkResult = await insforge.auth.resetPassword({
|
|
257
|
+
newPassword,
|
|
258
|
+
otp: token
|
|
259
|
+
});
|
|
240
260
|
return sdkResult.data;
|
|
241
261
|
},
|
|
242
262
|
[insforge]
|
|
@@ -264,7 +284,8 @@ function InsforgeProvider({
|
|
|
264
284
|
baseUrl,
|
|
265
285
|
sendPasswordResetCode,
|
|
266
286
|
resetPassword,
|
|
267
|
-
verifyEmail
|
|
287
|
+
verifyEmail,
|
|
288
|
+
getPublicAuthConfig
|
|
268
289
|
},
|
|
269
290
|
children
|
|
270
291
|
}
|
|
@@ -278,42 +299,23 @@ function useInsforge() {
|
|
|
278
299
|
return context;
|
|
279
300
|
}
|
|
280
301
|
function usePublicAuthConfig() {
|
|
281
|
-
const {
|
|
282
|
-
const [oauthProviders, setOAuthProviders] = useState([]);
|
|
302
|
+
const { getPublicAuthConfig } = useInsforge();
|
|
283
303
|
const [emailConfig, setEmailConfig] = useState(null);
|
|
284
304
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
285
305
|
useEffect(() => {
|
|
286
|
-
let mounted = true;
|
|
287
306
|
async function fetchConfig() {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
setEmailConfig(null);
|
|
295
|
-
} else {
|
|
296
|
-
const data = await response.json();
|
|
297
|
-
const providerNames = data.providers?.map((p) => p.provider) || [];
|
|
298
|
-
setOAuthProviders(providerNames);
|
|
299
|
-
setEmailConfig(data.email || null);
|
|
300
|
-
}
|
|
301
|
-
setIsLoaded(true);
|
|
302
|
-
} catch (error) {
|
|
303
|
-
console.warn("[usePublicAuthConfig] Unexpected error:", error);
|
|
304
|
-
if (mounted) {
|
|
305
|
-
setOAuthProviders([]);
|
|
306
|
-
setEmailConfig(null);
|
|
307
|
-
setIsLoaded(true);
|
|
308
|
-
}
|
|
307
|
+
const result = await getPublicAuthConfig();
|
|
308
|
+
if (result) {
|
|
309
|
+
setEmailConfig(result);
|
|
310
|
+
} else {
|
|
311
|
+
console.error("[usePublicAuthConfig] Failed to get public auth config");
|
|
312
|
+
setEmailConfig(null);
|
|
309
313
|
}
|
|
314
|
+
setIsLoaded(true);
|
|
310
315
|
}
|
|
311
316
|
fetchConfig();
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
};
|
|
315
|
-
}, [baseUrl]);
|
|
316
|
-
return { oauthProviders, emailConfig, isLoaded };
|
|
317
|
+
}, [getPublicAuthConfig]);
|
|
318
|
+
return { emailConfig, isLoaded };
|
|
317
319
|
}
|
|
318
320
|
function AuthBranding() {
|
|
319
321
|
return /* @__PURE__ */ jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
|
|
@@ -665,6 +667,22 @@ function AuthSubmitButton({
|
|
|
665
667
|
);
|
|
666
668
|
}
|
|
667
669
|
function AuthLink({ text, linkText, href, appearance = {} }) {
|
|
670
|
+
const currentSearch = typeof window !== "undefined" ? window.location.search : "";
|
|
671
|
+
const finalHref = (() => {
|
|
672
|
+
if (!currentSearch) return href;
|
|
673
|
+
try {
|
|
674
|
+
const url = new URL(href, window.location.origin);
|
|
675
|
+
const currentParams = new URLSearchParams(currentSearch);
|
|
676
|
+
currentParams.forEach((value, key) => {
|
|
677
|
+
if (!url.searchParams.has(key)) {
|
|
678
|
+
url.searchParams.set(key, value);
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
return url.pathname + url.search;
|
|
682
|
+
} catch {
|
|
683
|
+
return href;
|
|
684
|
+
}
|
|
685
|
+
})();
|
|
668
686
|
return /* @__PURE__ */ jsxs("p", { className: cn(
|
|
669
687
|
"text-center text-sm font-normal text-[#828282] leading-6",
|
|
670
688
|
appearance.containerClassName
|
|
@@ -674,7 +692,7 @@ function AuthLink({ text, linkText, href, appearance = {} }) {
|
|
|
674
692
|
/* @__PURE__ */ jsx(
|
|
675
693
|
"a",
|
|
676
694
|
{
|
|
677
|
-
href,
|
|
695
|
+
href: finalHref,
|
|
678
696
|
className: cn(
|
|
679
697
|
"text-sm font-medium text-black leading-6",
|
|
680
698
|
appearance.linkClassName
|
|
@@ -1184,7 +1202,7 @@ function SignIn({
|
|
|
1184
1202
|
...uiProps
|
|
1185
1203
|
}) {
|
|
1186
1204
|
const { signIn, baseUrl } = useInsforge();
|
|
1187
|
-
const {
|
|
1205
|
+
const { emailConfig } = usePublicAuthConfig();
|
|
1188
1206
|
const [email, setEmail] = useState("");
|
|
1189
1207
|
const [password, setPassword] = useState("");
|
|
1190
1208
|
const [error, setError] = useState("");
|
|
@@ -1236,7 +1254,9 @@ function SignIn({
|
|
|
1236
1254
|
setOauthLoading(null);
|
|
1237
1255
|
}
|
|
1238
1256
|
}
|
|
1239
|
-
if (!emailConfig)
|
|
1257
|
+
if (!emailConfig) {
|
|
1258
|
+
return null;
|
|
1259
|
+
}
|
|
1240
1260
|
return /* @__PURE__ */ jsx(
|
|
1241
1261
|
SignInForm,
|
|
1242
1262
|
{
|
|
@@ -1248,7 +1268,7 @@ function SignIn({
|
|
|
1248
1268
|
error,
|
|
1249
1269
|
loading,
|
|
1250
1270
|
oauthLoading,
|
|
1251
|
-
availableProviders:
|
|
1271
|
+
availableProviders: emailConfig?.oAuthProviders || [],
|
|
1252
1272
|
onOAuthClick: handleOAuth,
|
|
1253
1273
|
emailAuthConfig: emailConfig,
|
|
1254
1274
|
...uiProps
|
|
@@ -1411,7 +1431,7 @@ function SignUp({
|
|
|
1411
1431
|
...uiProps
|
|
1412
1432
|
}) {
|
|
1413
1433
|
const { signUp, baseUrl } = useInsforge();
|
|
1414
|
-
const {
|
|
1434
|
+
const { emailConfig } = usePublicAuthConfig();
|
|
1415
1435
|
const [email, setEmail] = useState("");
|
|
1416
1436
|
const [password, setPassword] = useState("");
|
|
1417
1437
|
const [error, setError] = useState("");
|
|
@@ -1468,7 +1488,9 @@ function SignUp({
|
|
|
1468
1488
|
setOauthLoading(null);
|
|
1469
1489
|
}
|
|
1470
1490
|
}
|
|
1471
|
-
if (!emailConfig)
|
|
1491
|
+
if (!emailConfig) {
|
|
1492
|
+
return null;
|
|
1493
|
+
}
|
|
1472
1494
|
return /* @__PURE__ */ jsx(
|
|
1473
1495
|
SignUpForm,
|
|
1474
1496
|
{
|
|
@@ -1480,7 +1502,7 @@ function SignUp({
|
|
|
1480
1502
|
error,
|
|
1481
1503
|
loading,
|
|
1482
1504
|
oauthLoading,
|
|
1483
|
-
availableProviders:
|
|
1505
|
+
availableProviders: emailConfig?.oAuthProviders || [],
|
|
1484
1506
|
onOAuthClick: handleOAuth,
|
|
1485
1507
|
emailAuthConfig: emailConfig,
|
|
1486
1508
|
...uiProps
|