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

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

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

Loading…
Cancel
Save