1

there are many APIs on my react app. my APIs is like the following:

return axios
.request({
  url: apiURLs.getSites,
  method: "get",
  headers: authHeader(),
})
.then((res) => res.data)

I have a problem. I need to redirect the login page when API res get the token expired error message.

return axios
    .request({
        url: apiURLs.getSites,
        method: "get",
        headers: authHeader(),
    })
    .then(
        (res) => res.data,
        (error) => **redirect login page**
    )

current my solution is like the above. but I don't like this way because I have to paste the redirect function on all api call part. this is not really efficient.

before on Angular 8, for this, I used HttpInterceptor. this is very good for me.

what is the best way for this? please let me know. thanks

forevereffort
  • 432
  • 1
  • 3
  • 14

0 Answers0