@insforge/react 0.2.3 → 0.2.5
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.js +46 -38
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +46 -38
- package/dist/components.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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +134 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -40
- package/dist/index.mjs.map +1 -1
- package/dist/router.js +26 -3
- package/dist/router.js.map +1 -1
- package/dist/router.mjs +26 -3
- 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/components.js
CHANGED
|
@@ -18,42 +18,23 @@ function useInsforge() {
|
|
|
18
18
|
return context;
|
|
19
19
|
}
|
|
20
20
|
function usePublicAuthConfig() {
|
|
21
|
-
const {
|
|
22
|
-
const [oauthProviders, setOAuthProviders] = react.useState([]);
|
|
21
|
+
const { getPublicAuthConfig } = useInsforge();
|
|
23
22
|
const [emailConfig, setEmailConfig] = react.useState(null);
|
|
24
23
|
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
25
24
|
react.useEffect(() => {
|
|
26
|
-
let mounted = true;
|
|
27
25
|
async function fetchConfig() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setEmailConfig(null);
|
|
35
|
-
} else {
|
|
36
|
-
const data = await response.json();
|
|
37
|
-
const providerNames = data.providers?.map((p) => p.provider) || [];
|
|
38
|
-
setOAuthProviders(providerNames);
|
|
39
|
-
setEmailConfig(data.email || null);
|
|
40
|
-
}
|
|
41
|
-
setIsLoaded(true);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.warn("[usePublicAuthConfig] Unexpected error:", error);
|
|
44
|
-
if (mounted) {
|
|
45
|
-
setOAuthProviders([]);
|
|
46
|
-
setEmailConfig(null);
|
|
47
|
-
setIsLoaded(true);
|
|
48
|
-
}
|
|
26
|
+
const result = await getPublicAuthConfig();
|
|
27
|
+
if (result) {
|
|
28
|
+
setEmailConfig(result);
|
|
29
|
+
} else {
|
|
30
|
+
console.error("[usePublicAuthConfig] Failed to get public auth config");
|
|
31
|
+
setEmailConfig(null);
|
|
49
32
|
}
|
|
33
|
+
setIsLoaded(true);
|
|
50
34
|
}
|
|
51
35
|
fetchConfig();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
}, [baseUrl]);
|
|
56
|
-
return { oauthProviders, emailConfig, isLoaded };
|
|
36
|
+
}, [getPublicAuthConfig]);
|
|
37
|
+
return { emailConfig, isLoaded };
|
|
57
38
|
}
|
|
58
39
|
function AuthBranding() {
|
|
59
40
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
|
|
@@ -937,7 +918,7 @@ function SignIn({
|
|
|
937
918
|
...uiProps
|
|
938
919
|
}) {
|
|
939
920
|
const { signIn, baseUrl } = useInsforge();
|
|
940
|
-
const {
|
|
921
|
+
const { emailConfig } = usePublicAuthConfig();
|
|
941
922
|
const [email, setEmail] = react.useState("");
|
|
942
923
|
const [password, setPassword] = react.useState("");
|
|
943
924
|
const [error, setError] = react.useState("");
|
|
@@ -989,7 +970,9 @@ function SignIn({
|
|
|
989
970
|
setOauthLoading(null);
|
|
990
971
|
}
|
|
991
972
|
}
|
|
992
|
-
if (!emailConfig)
|
|
973
|
+
if (!emailConfig) {
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
993
976
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
994
977
|
SignInForm,
|
|
995
978
|
{
|
|
@@ -1001,7 +984,7 @@ function SignIn({
|
|
|
1001
984
|
error,
|
|
1002
985
|
loading,
|
|
1003
986
|
oauthLoading,
|
|
1004
|
-
availableProviders:
|
|
987
|
+
availableProviders: emailConfig?.oAuthProviders || [],
|
|
1005
988
|
onOAuthClick: handleOAuth,
|
|
1006
989
|
emailAuthConfig: emailConfig,
|
|
1007
990
|
...uiProps
|
|
@@ -1164,7 +1147,7 @@ function SignUp({
|
|
|
1164
1147
|
...uiProps
|
|
1165
1148
|
}) {
|
|
1166
1149
|
const { signUp, baseUrl } = useInsforge();
|
|
1167
|
-
const {
|
|
1150
|
+
const { emailConfig } = usePublicAuthConfig();
|
|
1168
1151
|
const [email, setEmail] = react.useState("");
|
|
1169
1152
|
const [password, setPassword] = react.useState("");
|
|
1170
1153
|
const [error, setError] = react.useState("");
|
|
@@ -1221,7 +1204,9 @@ function SignUp({
|
|
|
1221
1204
|
setOauthLoading(null);
|
|
1222
1205
|
}
|
|
1223
1206
|
}
|
|
1224
|
-
if (!emailConfig)
|
|
1207
|
+
if (!emailConfig) {
|
|
1208
|
+
return null;
|
|
1209
|
+
}
|
|
1225
1210
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1226
1211
|
SignUpForm,
|
|
1227
1212
|
{
|
|
@@ -1233,7 +1218,7 @@ function SignUp({
|
|
|
1233
1218
|
error,
|
|
1234
1219
|
loading,
|
|
1235
1220
|
oauthLoading,
|
|
1236
|
-
availableProviders:
|
|
1221
|
+
availableProviders: emailConfig?.oAuthProviders || [],
|
|
1237
1222
|
onOAuthClick: handleOAuth,
|
|
1238
1223
|
emailAuthConfig: emailConfig,
|
|
1239
1224
|
...uiProps
|
|
@@ -1424,7 +1409,7 @@ function InsforgeCallback({
|
|
|
1424
1409
|
onRedirect
|
|
1425
1410
|
}) {
|
|
1426
1411
|
const isProcessingRef = react.useRef(false);
|
|
1427
|
-
const {
|
|
1412
|
+
const { handleAuthCallback } = useInsforge();
|
|
1428
1413
|
react.useEffect(() => {
|
|
1429
1414
|
const processCallback = async () => {
|
|
1430
1415
|
if (isProcessingRef.current) return;
|
|
@@ -1444,7 +1429,30 @@ function InsforgeCallback({
|
|
|
1444
1429
|
}
|
|
1445
1430
|
return;
|
|
1446
1431
|
}
|
|
1447
|
-
const
|
|
1432
|
+
const accessToken = searchParams.get("access_token") || searchParams.get("auth_token");
|
|
1433
|
+
const userId = searchParams.get("user_id");
|
|
1434
|
+
const email = searchParams.get("email");
|
|
1435
|
+
const name = searchParams.get("name");
|
|
1436
|
+
if (!accessToken) {
|
|
1437
|
+
const errorMsg = "no_token";
|
|
1438
|
+
if (onError) {
|
|
1439
|
+
onError(errorMsg);
|
|
1440
|
+
} else {
|
|
1441
|
+
const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
|
|
1442
|
+
if (onRedirect) {
|
|
1443
|
+
onRedirect(errorUrl);
|
|
1444
|
+
} else {
|
|
1445
|
+
window.location.href = errorUrl;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
const result = await handleAuthCallback({
|
|
1451
|
+
accessToken,
|
|
1452
|
+
userId: userId || void 0,
|
|
1453
|
+
email: email || void 0,
|
|
1454
|
+
name: name || void 0
|
|
1455
|
+
});
|
|
1448
1456
|
if (!result.success) {
|
|
1449
1457
|
const errorMsg = result.error || "authentication_failed";
|
|
1450
1458
|
if (onError) {
|
|
@@ -1473,7 +1481,7 @@ function InsforgeCallback({
|
|
|
1473
1481
|
}
|
|
1474
1482
|
};
|
|
1475
1483
|
processCallback();
|
|
1476
|
-
}, []);
|
|
1484
|
+
}, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
|
|
1477
1485
|
const defaultLoading = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
|
|
1478
1486
|
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
|
|
1479
1487
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })
|