|
|
|
|
@ -6,10 +6,11 @@ import { |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import { loginCheck } from 'features/AuthServiceApp/requests/authСheck' |
|
|
|
|
import { authorize } 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' |
|
|
|
|
|
|
|
|
|
const url = getApiUrl('/authorize') |
|
|
|
|
@ -22,6 +23,7 @@ export const useLoginForm = () => { |
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false) |
|
|
|
|
|
|
|
|
|
const formRef = useRef<HTMLFormElement>(null) |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
email, |
|
|
|
|
error: formError, |
|
|
|
|
@ -43,8 +45,19 @@ export const useLoginForm = () => { |
|
|
|
|
const handleModalOpen = () => { |
|
|
|
|
setIsModalOpen(true) |
|
|
|
|
} |
|
|
|
|
const submitForm = () => formRef.current?.submit() |
|
|
|
|
|
|
|
|
|
const redirect_url = new URLSearchParams(location.search).get('redirect_uri') |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
client_id, |
|
|
|
|
redirect_uri, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
} = getClientSettings() |
|
|
|
|
|
|
|
|
|
const redirect_url = new URLSearchParams(location.search).get('redirect_uri') || '' |
|
|
|
|
const currentRedirectUrl = redirect_url ?? redirect_uri |
|
|
|
|
|
|
|
|
|
const handleError = (error: string) => { |
|
|
|
|
setAuthError(error) |
|
|
|
|
@ -59,14 +72,9 @@ export const useLoginForm = () => { |
|
|
|
|
email, |
|
|
|
|
lang, |
|
|
|
|
password, |
|
|
|
|
redirect_url, |
|
|
|
|
currentRedirectUrl, |
|
|
|
|
) |
|
|
|
|
await (authorize( |
|
|
|
|
email, |
|
|
|
|
lang, |
|
|
|
|
password, |
|
|
|
|
redirect_url, |
|
|
|
|
)) |
|
|
|
|
submitForm() |
|
|
|
|
} catch (err) { |
|
|
|
|
handleError(String(err)) |
|
|
|
|
} |
|
|
|
|
@ -78,6 +86,7 @@ export const useLoginForm = () => { |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
authError, |
|
|
|
|
client_id, |
|
|
|
|
email, |
|
|
|
|
formError, |
|
|
|
|
formRef, |
|
|
|
|
@ -86,11 +95,16 @@ export const useLoginForm = () => { |
|
|
|
|
isFetching, |
|
|
|
|
isModalOpen, |
|
|
|
|
isSubmitDisabled, |
|
|
|
|
lang, |
|
|
|
|
onEmailBlur, |
|
|
|
|
onEmailChange, |
|
|
|
|
onPasswordBlur, |
|
|
|
|
onPasswordChange, |
|
|
|
|
password, |
|
|
|
|
redirect_uri: currentRedirectUrl, |
|
|
|
|
response_mode, |
|
|
|
|
response_type, |
|
|
|
|
scope, |
|
|
|
|
setIsModalOpen, |
|
|
|
|
url, |
|
|
|
|
} |
|
|
|
|
|