fix(#2244): add client_id in post params for change password

keep-around/20e770c4c097d7291fab6e52719ce73c8a335f99
Andrei Dekterev 4 years ago
parent fc1872d034
commit 0a35f60bb5
  1. 17
      src/features/AuthServiceApp/components/ChangePassword/hooks.tsx
  2. 8
      src/features/AuthServiceApp/components/RecoveryPopup/hooks.tsx
  3. 9
      src/features/AuthServiceApp/requests/changePassword.tsx

@ -4,10 +4,17 @@ import {
useState,
} from 'react'
import { useLocation, useHistory } from 'react-router'
import { ClientIds } from 'config/clients/types'
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields'
import { changePassword } from 'features/AuthServiceApp/requests/changePassword'
import { getClientSettings } from 'features/AuthStore/helpers'
export const useChangePasswordForm = () => {
const location = useLocation()
const history = useHistory()
const [error, setError] = useState('')
const [isFetching, setIsFetching] = useState(false)
const [password, setPassword] = useState('')
@ -18,16 +25,18 @@ export const useChangePasswordForm = () => {
checkPassword,
} = useAuthFields('login')
const { client_id } = getClientSettings()
const currentClientId = new URLSearchParams(location.search).get('client_id') ?? client_id
const handleSubmit = async (event: SyntheticEvent) => {
event?.preventDefault()
setIsFetching(true)
try {
const redirectUrl = await changePassword(password)
await changePassword(currentClientId as ClientIds, password)
setError('')
setIsFetching(false)
if (redirectUrl) {
await window.location.assign(redirectUrl)
}
history.push(`/autorize?client_id=${currentClientId}`)
} catch (err) {
setError(String(err))
setIsFetching(false)

@ -47,8 +47,10 @@ export const useRecovery = (setIsModalOpen: (value: boolean) => void) => {
const handleSubmit = () => {
setIsFetching(true)
loginCheckChangePass(email, lang)
.then(() => setIsFetching(false))
.then(() => setIsSendMessage(true))
.then(() => {
setIsFetching(false)
setIsSendMessage(true)
})
.catch(handleError)
}
@ -58,7 +60,7 @@ export const useRecovery = (setIsModalOpen: (value: boolean) => void) => {
} else {
setIsSuccess(false)
}
}, [isSendMessage, isFetching])
}, [isFetching, isSendMessage])
return {
closePopup,

@ -1,3 +1,4 @@
import { ClientIds } from 'config/clients/types'
import { getApiUrl } from '../config/routes'
const errorLexics = {
@ -14,16 +15,14 @@ type FailedResponse = {
}
type SuccessResponse = {
data: {
url: string,
},
ok: true,
}
export const changePassword = async (password: string) => {
export const changePassword = async (currentClientId: ClientIds, password: string) => {
const url = getApiUrl('/change_password')
const init: RequestInit = {
body: new URLSearchParams({
client_id: currentClientId,
password,
}),
method: 'PUT',
@ -32,7 +31,7 @@ export const changePassword = async (password: string) => {
const body: SuccessResponse | FailedResponse = await response.json()
if (body.ok) return body.data.url
if (body.ok) return Promise.resolve()
return Promise.reject(errorLexics[body.error.code])
}

Loading…
Cancel
Save