diff --git a/client/src/hooks/use-auth.tsx b/client/src/hooks/use-auth.tsx index c314fee..bf6bcb0 100644 --- a/client/src/hooks/use-auth.tsx +++ b/client/src/hooks/use-auth.tsx @@ -13,11 +13,14 @@ type AuthContextType = { isLoading: boolean; error: Error | null; loginMutation: UseMutationResult; + ldapLoginMutation: UseMutationResult; + initiateOidcLogin: () => void; logoutMutation: UseMutationResult; registerMutation: UseMutationResult; }; type LoginData = Pick; +type LdapLoginData = Pick; export const AuthContext = createContext(null); @@ -74,6 +77,33 @@ export function AuthProvider({ children }: { children: ReactNode }) { }, }); + const ldapLoginMutation = useMutation({ + mutationFn: async (credentials: LdapLoginData) => { + const res = await apiRequest("POST", "/api/auth/ldap", credentials); + return await res.json(); + }, + onSuccess: (user: SelectUser) => { + queryClient.setQueryData(["/api/user"], user); + toast({ + title: "LDAP Login successful", + description: `Welcome back, ${user.username}!`, + }); + }, + onError: (error: Error) => { + toast({ + title: "LDAP Login failed", + description: error.message, + variant: "destructive", + }); + }, + }); + + // Function to initiate OIDC login flow + const initiateOidcLogin = () => { + // OpenID Connect requires a redirect to the provider's login page + window.location.href = "/api/auth/oidc"; + }; + const logoutMutation = useMutation({ mutationFn: async () => { await apiRequest("POST", "/api/logout"); @@ -101,6 +131,8 @@ export function AuthProvider({ children }: { children: ReactNode }) { isLoading, error, loginMutation, + ldapLoginMutation, + initiateOidcLogin, logoutMutation, registerMutation, }} diff --git a/client/src/pages/auth-page.tsx b/client/src/pages/auth-page.tsx index e487d31..64fc41a 100644 --- a/client/src/pages/auth-page.tsx +++ b/client/src/pages/auth-page.tsx @@ -206,10 +206,66 @@ export default function AuthPage() { + +
+
+ +
+
+ Or continue with +
+
+ +
+ + + +