You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
553 B
26 lines
553 B
import { useHistory } from 'react-router-dom'
|
|
|
|
import { PAGES } from 'config'
|
|
import { removeToken } from 'helpers'
|
|
// import { logout } from 'requests'
|
|
|
|
// временная заглушка запроса
|
|
const logout = () => Promise.resolve()
|
|
|
|
type Args = {
|
|
setToken: (token: string | null) => void,
|
|
}
|
|
|
|
export const useLogout = ({ setToken }: Args) => {
|
|
const history = useHistory()
|
|
|
|
const onSuccess = () => {
|
|
removeToken()
|
|
setToken(null)
|
|
history.replace(PAGES.login)
|
|
}
|
|
|
|
return async () => (
|
|
logout().then(onSuccess)
|
|
)
|
|
}
|
|
|