fix(#2244): fix client id with useParamsUrl

keep-around/20e770c4c097d7291fab6e52719ce73c8a335f99
Andrei Dekterev 4 years ago
parent 0a35f60bb5
commit 6e9ad037df
  1. 21
      src/features/AuthServiceApp/components/ChangePassword/hooks.tsx
  2. 8
      src/features/AuthServiceApp/requests/changePassword.tsx

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

@ -1,4 +1,5 @@
import { ClientIds } from 'config/clients/types'
import { getApiUrl } from '../config/routes'
const errorLexics = {
@ -18,13 +19,10 @@ type SuccessResponse = {
ok: true,
}
export const changePassword = async (currentClientId: ClientIds, password: string) => {
export const changePassword = async (client_id: ClientIds, password: string) => {
const url = getApiUrl('/change_password')
const init: RequestInit = {
body: new URLSearchParams({
client_id: currentClientId,
password,
}),
body: new URLSearchParams({ client_id, password }),
method: 'PUT',
}
const response = await fetch(url, init)

Loading…
Cancel
Save