I am using Vue + Axios + Vue Router + Vuex.
I want to handle authentication in Vue, after login, the user can do anything. But sometimes the token will be expired, and the server will give an error let's say Code = 123
. What I want is, I want to redirect the user to login page if the server gives me Code = 123
. I can check at every response of the axios, but it's not effective because there are hundreds of axios request that will affect .
Question:
- How to redirect if the server gives some error code like
Code = 123
? This happen to hundreds of axios response.
Please note that:
- It's server side checking, server can revoke token etc, so front end can't prevent token expiration.
- I don't want to write checking manually for hundreds responses in axios. It will be great if I can handle it in one place, so if I make a refactor it will be easy to do.