You probably have an /api/user
or /api/me
endpoint. Why not do it there instead of creating a dummy endpoint?
Another option is to use axios
interceptors: https://axios-http.com/docs/interceptors
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response.status === 401) {
dispatch(logoutUser()) // probably needs a debounce
}
return Promise.reject(error)
})