|
|
|
|
@ -7,17 +7,21 @@ import { |
|
|
|
|
|
|
|
|
|
import { loginCheck } from 'features/AuthServiceApp/requests/auth' |
|
|
|
|
import { getApiUrl } from 'features/AuthServiceApp/config/routes' |
|
|
|
|
import { useLexicsStore } from 'features/LexicsStore' |
|
|
|
|
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' |
|
|
|
|
import { getClientSettings } from 'features/AuthStore/helpers' |
|
|
|
|
|
|
|
|
|
import { useLocation } from 'react-router' |
|
|
|
|
import { useParamsUrl } from '../../hooks/useParamsUrl' |
|
|
|
|
|
|
|
|
|
const url = getApiUrl('/authorize') |
|
|
|
|
|
|
|
|
|
export const useLoginForm = () => { |
|
|
|
|
const location = useLocation() |
|
|
|
|
const { lang } = useLexicsStore() |
|
|
|
|
const { |
|
|
|
|
client_id, |
|
|
|
|
lang, |
|
|
|
|
redirect_uri, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
} = useParamsUrl() |
|
|
|
|
const [authError, setAuthError] = useState('') |
|
|
|
|
const [isFetching, setIsFetching] = useState(false) |
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false) |
|
|
|
|
@ -47,20 +51,6 @@ export const useLoginForm = () => { |
|
|
|
|
} |
|
|
|
|
const submitForm = () => formRef.current?.submit() |
|
|
|
|
|
|
|
|
|
const redirect_url = new URLSearchParams(location.search).get('redirect_uri') |
|
|
|
|
const clientId = new URLSearchParams(location.search).get('client_id') |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
client_id, |
|
|
|
|
redirect_uri, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
} = getClientSettings() |
|
|
|
|
|
|
|
|
|
const currentRedirectUrl = redirect_url ?? redirect_uri |
|
|
|
|
const currentClientId = clientId ?? client_id |
|
|
|
|
|
|
|
|
|
const handleError = (error: string) => { |
|
|
|
|
setAuthError(error) |
|
|
|
|
setIsFetching(false) |
|
|
|
|
@ -70,13 +60,18 @@ export const useLoginForm = () => { |
|
|
|
|
e.preventDefault() |
|
|
|
|
setIsFetching(true) |
|
|
|
|
try { |
|
|
|
|
await loginCheck( |
|
|
|
|
currentClientId, |
|
|
|
|
await loginCheck({ |
|
|
|
|
email, |
|
|
|
|
lang, |
|
|
|
|
password, |
|
|
|
|
currentRedirectUrl, |
|
|
|
|
) |
|
|
|
|
urlParams: { |
|
|
|
|
client_id, |
|
|
|
|
lang, |
|
|
|
|
redirect_uri, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
submitForm() |
|
|
|
|
} catch (err) { |
|
|
|
|
handleError(String(err)) |
|
|
|
|
@ -89,7 +84,7 @@ export const useLoginForm = () => { |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
authError, |
|
|
|
|
client_id: currentClientId, |
|
|
|
|
client_id, |
|
|
|
|
email, |
|
|
|
|
formError, |
|
|
|
|
formRef, |
|
|
|
|
@ -104,7 +99,7 @@ export const useLoginForm = () => { |
|
|
|
|
onPasswordBlur, |
|
|
|
|
onPasswordChange, |
|
|
|
|
password, |
|
|
|
|
redirect_uri: currentRedirectUrl, |
|
|
|
|
redirect_uri, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
|