fix(2290): fix send post params from url in registration

keep-around/1d06f55c2b729e25cd8684a146a86df6860d2876
Andrei Dekterev 4 years ago
parent 9f218b345a
commit 04609ac480
  1. 6
      src/features/AuthServiceApp/components/Registration/hooks.tsx
  2. 31
      src/features/AuthServiceApp/hooks/useParamsUrl.tsx
  3. 34
      src/features/AuthServiceApp/requests/register.tsx

@ -1,11 +1,12 @@
import { SyntheticEvent, useState } from 'react'
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields'
import { useLexicsStore } from 'features/LexicsStore'
import { registerCheck } from '../../requests/register'
import { useParamsUrl } from '../../hooks/useParamsUrl'
export const useRegistrationForm = () => {
const urlParams = useParamsUrl()
const [authError, setAuthError] = useState('')
const [termsAccepted, setTermsAccepted] = useState(false)
const [isFetching, setIsFetching] = useState(false)
@ -27,7 +28,6 @@ export const useRegistrationForm = () => {
|| Boolean(formError)
|| isFetching
)
const { lang } = useLexicsStore()
const handleSubmit = async (event: SyntheticEvent) => {
event?.preventDefault()
@ -35,8 +35,8 @@ export const useRegistrationForm = () => {
try {
await registerCheck({
email,
lang,
password,
urlParams,
})
setAuthError('')
setIsFetching(false)

@ -0,0 +1,31 @@
import { useLocation } from 'react-router'
import { getClientSettings } from 'features/AuthStore/helpers'
import { useLexicsStore } from 'features/LexicsStore'
export const useParamsUrl = () => {
const location = useLocation()
const { lang } = useLexicsStore()
const {
client_id,
redirect_uri,
response_mode,
response_type,
scope,
} = getClientSettings()
const urlSearchParams = new URLSearchParams(location.search)
const params = Object.fromEntries(urlSearchParams.entries())
return {
client_id,
redirect_uri,
response_mode,
response_type,
scope,
...params,
lang,
}
}

@ -1,7 +1,5 @@
import { getApiUrl } from 'features/AuthServiceApp/config/routes'
import { getClientSettings } from 'features/AuthStore/helpers'
const errorLexics = {
1: 'error_invalid_email_or_password',
2: 'error_missing_required_argument',
@ -25,39 +23,31 @@ type SuccessResponse = {
type RegisterProps = {
email: string,
lang?: string,
lang?: string | undefined,
password: string,
urlParams: {
client_id?: string,
none?: string,
redirect_uri?: string,
response_mode?: string,
response_type?: string,
scope?: string,
state?: string,
},
}
export const registerCheck = async ({
email,
lang,
password,
urlParams,
} : RegisterProps) => {
const {
client_id,
redirect_uri,
response_mode,
response_type,
scope,
} = getClientSettings()
const url = getApiUrl('/registration')
const paramsUrl = {
client_id,
lang,
redirect_uri,
response_mode,
response_type,
scope,
}
const init: RequestInit = {
body: new URLSearchParams({
email,
password,
...paramsUrl as {},
...urlParams as {},
}),
method: 'POST',
}

Loading…
Cancel
Save