diff --git a/client/src/hooks/use-auth.tsx b/client/src/hooks/use-auth.tsx index 5a76c75..998c4d3 100644 --- a/client/src/hooks/use-auth.tsx +++ b/client/src/hooks/use-auth.tsx @@ -1,4 +1,4 @@ -import { createContext, ReactNode, useContext } from "react"; +import { createContext, ReactNode, useContext, useEffect, useState } from "react"; import { useQuery, useMutation, @@ -17,6 +17,8 @@ type AuthContextType = { initiateOidcLogin: () => void; logoutMutation: UseMutationResult; registerMutation: UseMutationResult; + ldapEnabled: boolean; + oidcEnabled: boolean; }; type LoginData = Pick; @@ -26,6 +28,9 @@ export const AuthContext = createContext(null); export function AuthProvider({ children }: { children: ReactNode }) { const { toast } = useToast(); + const [ldapEnabled, setLdapEnabled] = useState(false); + const [oidcEnabled, setOidcEnabled] = useState(false); + const { data: user, error, @@ -34,6 +39,25 @@ export function AuthProvider({ children }: { children: ReactNode }) { queryKey: ["/api/user"], queryFn: getQueryFn({ on401: "returnNull" }), }); + + // Get auth provider configurations + useEffect(() => { + const fetchAuthProviders = async () => { + try { + const response = await fetch('/api/auth/providers'); + if (response.ok) { + const providers = await response.json(); + setLdapEnabled(providers.ldap?.enabled || false); + setOidcEnabled(providers.oidc?.enabled || false); + } + } catch (err) { + // Silently fail - default is disabled + console.error('Failed to fetch auth providers:', err); + } + }; + + fetchAuthProviders(); + }, []); const loginMutation = useMutation({ mutationFn: async (credentials: LoginData) => { @@ -133,6 +157,8 @@ export function AuthProvider({ children }: { children: ReactNode }) { initiateOidcLogin, logoutMutation, registerMutation, + ldapEnabled, + oidcEnabled, }; return ( diff --git a/client/src/pages/auth-page.tsx b/client/src/pages/auth-page.tsx index 5b1cc14..c1f6e29 100644 --- a/client/src/pages/auth-page.tsx +++ b/client/src/pages/auth-page.tsx @@ -234,61 +234,70 @@ export default function AuthPage() { {auth.loginMutation.isPending ? "Logging in..." : "Log in"} -
-
- -
-
- Or continue with -
-
- -
- + )} - // Validate the fields - if (!username || !password) { - loginForm.setError("username", { - type: "manual", - message: !username ? "Username is required" : undefined - }); - loginForm.setError("password", { - type: "manual", - message: !password ? "Password is required" : undefined - }); - return; - } - - auth.ldapLoginMutation.mutate( - { username, password }, - { - onSuccess: () => { - navigate("/"); - } - } - ); - }} - > - {auth.ldapLoginMutation.isPending ? "Authenticating..." : "LDAP Login"} - - - -
+ {auth.oidcEnabled && ( + + )} + + + )}