Vue-Laravel-SPA
Vue-Laravel-SPA copied to clipboard
Passing token via general.js file
axios.defaults.headers.common["Authorization"] does not work. Each request call says "Token not provided". Would be nice if you fixed.
@emil126a
I had the same issue with the Authorization Header is not set after page refresh.
I solve this by creating created method and reinitialize the Authorization Header if user is found in the local storage.
var app = new Vue({
el: '#app',
router,
store,
components: {
'main-app': MainComponent
},
created() {
const user = getUser();
if(user) {
setAuthenticationHeader(user.token);
}
}
});
Make sure the value of Authorization has a prefix of "Bearer "+token Take note it should have a space in between, something like "Bearer ad45tegdzgftryhgcxbsydhtv5y"
const user = getUser();
getUser is not defined...
Ah. Sorry I forgot to mention. You gotta have to import those methods from auth.js in helper folder. LIke This
import {setAuthenticationHeader, getUser} from './helpers/auth';