fix(#184): make request on logout (#42)

keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent 2bdde0a79a
commit 3d8f1637c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/config/procedures.tsx
  2. 12
      src/features/AuthStore/hooks/useLogout.tsx
  3. 1
      src/requests/index.tsx
  4. 18
      src/requests/logout.tsx

@ -3,6 +3,7 @@ export const PROCEDURES = {
create_user: 'create_user',
get_cities: 'get_cities',
get_players_teams_tournaments: 'get_players_teams_tournaments',
logout_user: 'logout_user',
lst_c_country: 'lst_c_country',
param_lexical: 'param_lexical',
}

@ -2,10 +2,7 @@ import { useHistory } from 'react-router-dom'
import { PAGES } from 'config'
import { removeToken } from 'helpers'
// import { logout } from 'requests'
// временная заглушка запроса
const logout = () => Promise.resolve()
import { logout } from 'requests'
type Args = {
setToken: (token: string | null) => void,
@ -14,13 +11,10 @@ type Args = {
export const useLogout = ({ setToken }: Args) => {
const history = useHistory()
const onSuccess = () => {
return () => {
logout()
removeToken()
setToken(null)
history.replace(PAGES.login)
}
return async () => (
logout().then(onSuccess)
)
}

@ -1,5 +1,6 @@
export * from './register'
export * from './login'
export * from './logout'
export * from './getCountries'
export * from './getCountryCities'
export * from './getLexics'

@ -0,0 +1,18 @@
import { DATA_URL, PROCEDURES } from 'config'
import { callApi } from 'helpers'
const proc = PROCEDURES.logout_user
export const logout = () => {
const config = {
body: {
params: {},
proc,
},
}
callApi({
config,
url: DATA_URL,
})
}
Loading…
Cancel
Save