Next.js Discord

Discord Forum

redirection does not work

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
axiosUser.interceptors.response.use(
    (response) => {
      return response;
    },
    (error) => {
      if (error.response && error.response.status === 403) {
        Cookies.remove('auth_token');
        const router = useRouter();
        return router.push('/auth/login');
      }
      return Promise.reject(error);
    }
  );

I'm using axios to check all requests made here.
If the status is 403, it is because the token is invalid and the user must go to the login page.
But when this happens, nothing happens, the user doesn't go to login, he just stays on the same page.
I already tried with redirect()

What could it be?

1 Reply