Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ui/src/components/views/auth/auth-ldap-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const AuthLdapPage = () => {
const [usernameError, setUsernameError] = useState('')
const [passwordError, setPasswordError] = useState('')
const [formError, setFormError] = useState('')
const { data: authData, error, mutate: auth, isSuccess } = useLdapAuth()
const { data: authData, error, mutate: auth, isSuccess, isPending } = useLdapAuth()
const { data: authContact } = useGetAuthContact()

const onFormSubmit = async (event: FormEvent<HTMLFormElement>) => {
Expand Down Expand Up @@ -51,8 +51,8 @@ export const AuthLdapPage = () => {
}, [authData])

useEffect(() => {
if (error?.response?.data.error === 'ValidationError') {
for (const item of error.response.data.validationErrors) {
if (error?.data.error === 'ValidationError') {
for (const item of error.data.validationErrors) {
if (item.param === 'username') {
setUsernameError(item.msg)
}
Expand All @@ -65,13 +65,13 @@ export const AuthLdapPage = () => {
return
}

if (error?.response?.data.error === 'InvalidCredentialsError') {
if (error?.data.error === 'InvalidCredentialsError') {
setFormError('Incorrect login details')

return
}

if (error?.response?.data.error) {
if (error?.data.error) {
setFormError('We do not recognize you. Please check your spelling and try again or use another login option')
}
}, [error])
Expand Down Expand Up @@ -113,7 +113,8 @@ export const AuthLdapPage = () => {
<Spacing size='xl' />
<FormItem>
<Button
disabled={!username || !password || !!usernameError || !!passwordError || !!formError}
disabled={!username || !password || !!usernameError || !!passwordError || isPending}
loading={isPending}
size='l'
type='submit'
stretched
Expand Down
4 changes: 2 additions & 2 deletions ui/src/lib/hooks/use-ldap-auth.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useMutation } from '@tanstack/react-query'

import { ldapAuth } from '@/api/auth'

import type { AxiosError } from 'axios'
import type { AxiosResponse } from 'axios'
import type { AuthResponse, LdapAuthArgs } from '@/api/auth/types'
import type { UseMutationResult } from '@tanstack/react-query'
import type { AuthErrorResponse } from '@/types/auth-error-response.type'

export const useLdapAuth = (): UseMutationResult<AuthResponse, AxiosError<AuthErrorResponse>, LdapAuthArgs> =>
export const useLdapAuth = (): UseMutationResult<AuthResponse, AxiosResponse<AuthErrorResponse>, LdapAuthArgs> =>
useMutation({
mutationFn: (data) => ldapAuth(data),
})
Loading