@insforge/react 0.2.3 → 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: [
@@ -935,7 +916,7 @@ function SignIn({
935
916
  ...uiProps
936
917
  }) {
937
918
  const { signIn, baseUrl } = useInsforge();
938
- const { oauthProviders, emailConfig } = usePublicAuthConfig();
919
+ const { emailConfig } = usePublicAuthConfig();
939
920
  const [email, setEmail] = useState("");
940
921
  const [password, setPassword] = useState("");
941
922
  const [error, setError] = useState("");
@@ -987,7 +968,9 @@ function SignIn({
987
968
  setOauthLoading(null);
988
969
  }
989
970
  }
990
- if (!emailConfig) return null;
971
+ if (!emailConfig) {
972
+ return null;
973
+ }
991
974
  return /* @__PURE__ */ jsx(
992
975
  SignInForm,
993
976
  {
@@ -999,7 +982,7 @@ function SignIn({
999
982
  error,
1000
983
  loading,
1001
984
  oauthLoading,
1002
- availableProviders: oauthProviders,
985
+ availableProviders: emailConfig?.oAuthProviders || [],
1003
986
  onOAuthClick: handleOAuth,
1004
987
  emailAuthConfig: emailConfig,
1005
988
  ...uiProps
@@ -1162,7 +1145,7 @@ function SignUp({
1162
1145
  ...uiProps
1163
1146
  }) {
1164
1147
  const { signUp, baseUrl } = useInsforge();
1165
- const { oauthProviders, emailConfig } = usePublicAuthConfig();
1148
+ const { emailConfig } = usePublicAuthConfig();
1166
1149
  const [email, setEmail] = useState("");
1167
1150
  const [password, setPassword] = useState("");
1168
1151
  const [error, setError] = useState("");
@@ -1219,7 +1202,9 @@ function SignUp({
1219
1202
  setOauthLoading(null);
1220
1203
  }
1221
1204
  }
1222
- if (!emailConfig) return null;
1205
+ if (!emailConfig) {
1206
+ return null;
1207
+ }
1223
1208
  return /* @__PURE__ */ jsx(
1224
1209
  SignUpForm,
1225
1210
  {
@@ -1231,7 +1216,7 @@ function SignUp({
1231
1216
  error,
1232
1217
  loading,
1233
1218
  oauthLoading,
1234
- availableProviders: oauthProviders,
1219
+ availableProviders: emailConfig?.oAuthProviders || [],
1235
1220
  onOAuthClick: handleOAuth,
1236
1221
  emailAuthConfig: emailConfig,
1237
1222
  ...uiProps