how can i set a default header with the jwt-token in all the request after login
-
i have tried the above on the picture however is saying it can find $store.
-
Are you using Vuex? Is it installed properly?
Scott
-
This post is deleted! -
@thamibn I always set the Axios header after the login. Before the login all requests are made without the Bearer token:
this.$http.post('/login', { username: this.email, password: this.password }) .then(res=> { localStorage.token = res.token; this.$http.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token; })
-
if you use axios, you can try this.
import axios from 'axios' setAxiosHeaders (token) { axios.defaults.headers.common['Authorization'] = 'Bearer ' + token }
-
@s-molinari yes it is installed properly
-
@jannerantala AND @KevinYang thanks you so much guys this worked!!!