From 6e9ad037df7dd3ed8977035f3f2a511120658673 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Wed, 2 Mar 2022 21:05:50 +0700 Subject: [PATCH] fix(#2244): fix client id with useParamsUrl --- .../components/ChangePassword/hooks.tsx | 21 +++++++------------ .../requests/changePassword.tsx | 8 +++---- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/features/AuthServiceApp/components/ChangePassword/hooks.tsx b/src/features/AuthServiceApp/components/ChangePassword/hooks.tsx index 73e6de32..ae9525e5 100644 --- a/src/features/AuthServiceApp/components/ChangePassword/hooks.tsx +++ b/src/features/AuthServiceApp/components/ChangePassword/hooks.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) diff --git a/src/features/AuthServiceApp/requests/changePassword.tsx b/src/features/AuthServiceApp/requests/changePassword.tsx index 4a07268a..63defc03 100644 --- a/src/features/AuthServiceApp/requests/changePassword.tsx +++ b/src/features/AuthServiceApp/requests/changePassword.tsx @@ -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)