Home > Software design >  Axios rewrites Authorization header
Axios rewrites Authorization header

Time:04-22

I am new in vuejs. Developing on Laravel8 Vuejs3. I have following code in vue:

methods: {
   getUsersList(url=null){
            let request_headers = {}
            request_headers['Accept'] = 'application/json'
            if(this.$store.state.token !== null) {
                request_headers['Authorization'] = 'Bearer '   ' '   this.$store.state.token
            }
            if(url == null) {
                url = this.API_URL   '/user/list'
            }
            axios
            .get(url, {headers: request_headers})
            .then(response => {
                if(response.data.result){
                    this.headers = response.data.data.headers;
                    this.body = response.data.data.body;
                }
            })}

console.log(request_headers['Authorization']) shows right token, but in request headers axios sends another token(all the time the same)

I don't know why. Please help. I tried a few solution like: creating new axios instance and adding default header manually

Helpless.

CodePudding user response:

Follow this set axios headers

Or create an instance by creating interceptor way - dont be frightened, its very easy

  • Related