The interceptor token, is added to vue-axios, but when some interfaces are requested, you don't need to take token, for example, to log in. How to operate this?

Global interceptor + token, is added to vue-axios, but some interfaces do not need to log in with token, when they are requested. How to do this

axios.interceptors.request.use (function (config) {

            config.headers["ApiAuth"] = sessionStorage.getItem("apiAuth");
            return config;
        });
Mar.18,2021

(1) Don't worry about it. If the interface doesn't need the token, backend, the people at the backend of the API will deal with it accordingly.
(2) the token value is returned to the front end by the backend after you first logged in, and then saved to the browser cache (which can also be obtained through the cache). It is impossible to return the token value every time the API is triggered. (even if token is time-limited, so don't worry)
(3) the global interceptor of axios does not seem to describe the situation you mentioned, at least there is no ~


when you log out, first empty the token at the front end, and then send the request


.

you can determine whether the current token exists, for example, before logging in, after logging out, and retrieving the password, which must be empty before logging in to get token. If it is empty, do not bring token information to the request.
if (getToken ()) {

config.headers['Authorization'] = `Token ${getToken()}`

}

Menu