Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs get token from header

I have a response from server and there are auth token, max age and some other values. In Postman it looks like: enter image description here

I want to set it to localStorage but have no idea how to get value in vuejs file, I tried this code:

this.$http.post('http://localhost:8081/login', data)
        .then(response =>{
          console.log(response.header.Authorization);
        })

but there is an error:

Uncaught (in promise) TypeError: Cannot read property 'Authorization' of undefined

how it it possible to read my token from header?

like image 422
littlewombat Avatar asked Feb 20 '26 20:02

littlewombat


1 Answers

Use headers

response.headers.get('Authorization');
like image 163
Bert Avatar answered Feb 22 '26 09:02

Bert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!