Open cannap opened 8 years ago
I'm a bit unclear on what you'd like to achieve. Are you wanting to send a header on the POST
request that you have in your login
method? Or are you wanting to set up a global Authorization
header with the user's JWT if login is successful?
Hi i solved with interceptors
Vue.http.interceptors.push((request, next) => {
const token = getLoginToken();
if (token) {
request.headers['Authorization'] = 'Bearer ' + token
}
next((response) => {
if (response.status === 401 && response.request.url !== "/session/create") {
//Todo: no hardcoded routes
window.location.pathname = "/admin/login"
}
});
});
The Tutorials show:
//index.js
Vue.http.headers.common['Authorization'] = auth.getAuthHeader();
but this will first work after a refresh
I have a question what is the best way to set the Header in auth.login() {}?
current solution:
import Vue from 'vue'; ....
i solve in a other way i switch to VUEX thank for the tutorial