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 { SyntheticEvent, useState } from 'react'
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields'
import { useLexicsStore } from 'features/LexicsStore'
import { registerCheck } from '../../requests/register' import { registerCheck } from '../../requests/register'
import { useParamsUrl } from '../../hooks/useParamsUrl'
export const useRegistrationForm = () => { export const useRegistrationForm = () => {
const urlParams = useParamsUrl()
const [authError, setAuthError] = useState('') const [authError, setAuthError] = useState('')
const [termsAccepted, setTermsAccepted] = useState(false) const [termsAccepted, setTermsAccepted] = useState(false)
const [isFetching, setIsFetching] = useState(false) const [isFetching, setIsFetching] = useState(false)
@ -27,7 +28,6 @@ export const useRegistrationForm = () => {
|| Boolean(formError) || Boolean(formError)
|| isFetching || isFetching
) )
const { lang } = useLexicsStore()
const handleSubmit = async (event: SyntheticEvent) => { const handleSubmit = async (event: SyntheticEvent) => {
event?.preventDefault() event?.preventDefault()
@ -35,8 +35,8 @@ export const useRegistrationForm = () => {
try { try {
await registerCheck({ await registerCheck({
email, email,
lang,
password, password,
urlParams,
}) })
setAuthError('') setAuthError('')
setIsFetching(false) 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 { getApiUrl } from 'features/AuthServiceApp/config/routes'
import { getClientSettings } from 'features/AuthStore/helpers'
const errorLexics = { const errorLexics = {
1: 'error_invalid_email_or_password', 1: 'error_invalid_email_or_password',
2: 'error_missing_required_argument', 2: 'error_missing_required_argument',
@ -25,39 +23,31 @@ type SuccessResponse = {
type RegisterProps = { type RegisterProps = {
email: string, email: string,
lang?: string, lang?: string | undefined,
password: string, 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 ({ export const registerCheck = async ({
email, email,
lang,
password, password,
urlParams,
} : RegisterProps) => { } : RegisterProps) => {
const {
client_id,
redirect_uri,
response_mode,
response_type,
scope,
} = getClientSettings()
const url = getApiUrl('/registration') const url = getApiUrl('/registration')
const paramsUrl = {
client_id,
lang,
redirect_uri,
response_mode,
response_type,
scope,
}
const init: RequestInit = { const init: RequestInit = {
body: new URLSearchParams({ body: new URLSearchParams({
email, email,
password, password,
...paramsUrl as {}, ...urlParams as {},
}), }),
method: 'POST', method: 'POST',
} }

Loading…
Cancel
Save