@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.
@@ -16,42 +16,23 @@ function useInsforge() {
16
16
  return context;
17
17
  }
18
18
  function usePublicAuthConfig() {
19
- const { baseUrl } = useInsforge();
20
- const [oauthProviders, setOAuthProviders] = useState([]);
19
+ const { getPublicAuthConfig } = useInsforge();
21
20
  const [emailConfig, setEmailConfig] = useState(null);
22
21
  const [isLoaded, setIsLoaded] = useState(false);
23
22
  useEffect(() => {
24
- let mounted = true;
25
23
  async function fetchConfig() {
26
- try {
27
- const response = await fetch(`${baseUrl}/api/auth/public-config`);
28
- if (!mounted) return;
29
- if (!response.ok) {
30
- console.warn("[usePublicAuthConfig] Failed to fetch public auth config:", response.statusText);
31
- setOAuthProviders([]);
32
- setEmailConfig(null);
33
- } else {
34
- const data = await response.json();
35
- const providerNames = data.providers?.map((p) => p.provider) || [];
36
- setOAuthProviders(providerNames);
37
- setEmailConfig(data.email || null);
38
- }
39
- setIsLoaded(true);
40
- } catch (error) {
41
- console.warn("[usePublicAuthConfig] Unexpected error:", error);
42
- if (mounted) {
43
- setOAuthProviders([]);
44
- setEmailConfig(null);
45
- setIsLoaded(true);
46
- }
24
+ const result = await getPublicAuthConfig();
25
+ if (result) {
26
+ setEmailConfig(result);
27
+ } else {
28
+ console.error("[usePublicAuthConfig] Failed to get public auth config");
29
+ setEmailConfig(null);
47
30
  }
31
+ setIsLoaded(true);
48
32
  }
49
33
  fetchConfig();
50
- return () => {
51
- mounted = false;
52
- };
53
- }, [baseUrl]);
54
- return { oauthProviders, emailConfig, isLoaded };
34
+ }, [getPublicAuthConfig]);
35
+ return { emailConfig, isLoaded };
55
36
  }
56
37
  function AuthBranding() {
57
38
  return /* @__PURE__ */ jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
@@ -403,6 +384,22 @@ function AuthSubmitButton({
403
384
  );
404
385
  }
405
386
  function AuthLink({ text, linkText, href, appearance = {} }) {
387
+ const currentSearch = typeof window !== "undefined" ? window.location.search : "";
388
+ const finalHref = (() => {
389
+ if (!currentSearch) return href;
390
+ try {
391
+ const url = new URL(href, window.location.origin);
392
+ const currentParams = new URLSearchParams(currentSearch);
393
+ currentParams.forEach((value, key) => {
394
+ if (!url.searchParams.has(key)) {
395
+ url.searchParams.set(key, value);
396
+ }
397
+ });
398
+ return url.pathname + url.search;
399
+ } catch {
400
+ return href;
401
+ }
402
+ })();
406
403
  return /* @__PURE__ */ jsxs("p", { className: cn(
407
404
  "text-center text-sm font-normal text-[#828282] leading-6",
408
405
  appearance.containerClassName
@@ -412,7 +409,7 @@ function AuthLink({ text, linkText, href, appearance = {} }) {
412
409
  /* @__PURE__ */ jsx(
413
410
  "a",
414
411
  {
415
- href,
412
+ href: finalHref,
416
413
  className: cn(
417
414
  "text-sm font-medium text-black leading-6",
418
415
  appearance.linkClassName
@@ -919,7 +916,7 @@ function SignIn({
919
916
  ...uiProps
920
917
  }) {
921
918
  const { signIn, baseUrl } = useInsforge();
922
- const { oauthProviders, emailConfig } = usePublicAuthConfig();
919
+ const { emailConfig } = usePublicAuthConfig();
923
920
  const [email, setEmail] = useState("");
924
921
  const [password, setPassword] = useState("");
925
922
  const [error, setError] = useState("");
@@ -971,7 +968,9 @@ function SignIn({
971
968
  setOauthLoading(null);
972
969
  }
973
970
  }
974
- if (!emailConfig) return null;
971
+ if (!emailConfig) {
972
+ return null;
973
+ }
975
974
  return /* @__PURE__ */ jsx(
976
975
  SignInForm,
977
976
  {
@@ -983,7 +982,7 @@ function SignIn({
983
982
  error,
984
983
  loading,
985
984
  oauthLoading,
986
- availableProviders: oauthProviders,
985
+ availableProviders: emailConfig?.oAuthProviders || [],
987
986
  onOAuthClick: handleOAuth,
988
987
  emailAuthConfig: emailConfig,
989
988
  ...uiProps
@@ -1146,7 +1145,7 @@ function SignUp({
1146
1145
  ...uiProps
1147
1146
  }) {
1148
1147
  const { signUp, baseUrl } = useInsforge();
1149
- const { oauthProviders, emailConfig } = usePublicAuthConfig();
1148
+ const { emailConfig } = usePublicAuthConfig();
1150
1149
  const [email, setEmail] = useState("");
1151
1150
  const [password, setPassword] = useState("");
1152
1151
  const [error, setError] = useState("");
@@ -1203,7 +1202,9 @@ function SignUp({
1203
1202
  setOauthLoading(null);
1204
1203
  }
1205
1204
  }
1206
- if (!emailConfig) return null;
1205
+ if (!emailConfig) {
1206
+ return null;
1207
+ }
1207
1208
  return /* @__PURE__ */ jsx(
1208
1209
  SignUpForm,
1209
1210
  {
@@ -1215,7 +1216,7 @@ function SignUp({
1215
1216
  error,
1216
1217
  loading,
1217
1218
  oauthLoading,
1218
- availableProviders: oauthProviders,
1219
+ availableProviders: emailConfig?.oAuthProviders || [],
1219
1220
  onOAuthClick: handleOAuth,
1220
1221
  emailAuthConfig: emailConfig,
1221
1222
  ...uiProps