0
I’m trying to set the headers - Authorization after a request via Xios, 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 into the headers in Authorization and after that redirect to the system home page on line 8. However the Authorization headers is not being created.
Someone would know to signal me where the bug is and how to create headers - Authorization with the token that is successfully returned in the rest of the . 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 })
Friend, your application is stateless? is a SPA? Post the code of this function "redirectPageHome" and an example of this "Sponse.data['base_url']". If your application is stateless, you must store the token locally (Storage location) and when loading the application perform the configuration.
– Paulo Sakamoto
It is stateless is not SPA, the "redirectPageHome" function performs only this -> window.location.replace(base_url+"/"). The base_url is brought in the answer of the Axios request.
– Jorgito da Silva Paiva