vue-resource interceptor for auth headers vue-resource interceptor for auth headers vue.js vue.js

vue-resource interceptor for auth headers


It turns out my problem was the syntax for which I was setting the headers in the interceptor.

It should be like this:

Vue.use(VueResource)Vue.http.interceptors.push((request, next) => {  request.headers.set('Authorization', 'Bearer eyJ0e.....etc')  request.headers.set('Accept', 'application/json')  next()})

While I was doing this:

Vue.use(VueResource)Vue.http.interceptors.push((request, next) => {  request.headers['Authorization'] = 'Bearer eyJ0e.....etc'  request.headers['Accept'] = 'application/json'  next()})


Add this option:

Vue.http.options.credentials = true;

And use the interceptors for global way:

Vue.http.interceptors.push(function(request, next) {request.headers['Authorization'] = 'Basic abc' //Base64request.headers['Accept'] = 'application/json'next()

});