I'm trying to set the headers - Authorization after a request via axios, this request returns the token that is generated on the server, in line 7 of the code below assign the token that is returned to insert in the headers in Authorization and after that redirect to the Home page of the system, at line 8. However headers Authorization is not being created.
Would anyone know how to signal where the error is and how do I create the headers - Authorization with the token that is successfully returned in .then, line 5?
1 data = {email: email, password: password};
2 url = '/auth/token';
3
4 axios.post(url, simpleQueryString.stringify(data))
5 .then(function(response) {
6 if (response.status == 201) {
7 window.axios.defaults.headers.common['Authorization'] = response.data.token;
8 redirectPageHome(response.data['base_url']);
9 }
10 })
11 .catch(function(error) {
12 console.log(error.response.data.error);
13 })