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, useState,
} from 'react' } from 'react'
import { useLocation, useHistory } from 'react-router' import { 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'
import { useParamsUrl } from '../../hooks/useParamsUrl'
export const useChangePasswordForm = () => { export const useChangePasswordForm = () => {
const location = useLocation() const { client_id } = useParamsUrl()
const history = useHistory() const history = useHistory()
const [error, setError] = useState('') const [error, setError] = useState('')
const [isFetching, setIsFetching] = useState(false) const [isFetching, setIsFetching] = useState(false)
@ -21,22 +20,16 @@ export const useChangePasswordForm = () => {
const [confirmPassword, setConfirmPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('')
const [disabled, setDisabled] = useState(true) const [disabled, setDisabled] = useState(true)
const { const { checkPassword } = useAuthFields('login')
checkPassword,
} = 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 {
await changePassword(currentClientId as ClientIds, password) await changePassword(client_id, password)
setError('') setError('')
setIsFetching(false) setIsFetching(false)
history.push(`/autorize?client_id=${currentClientId}`) history.push(`/autorize?client_id=${client_id}`)
} catch (err) { } catch (err) {
setError(String(err)) setError(String(err))
setIsFetching(false) setIsFetching(false)

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

Loading…
Cancel
Save