Add the authentication header after login

This commit is contained in:
nemunaire 2019-09-10 20:14:49 +02:00
parent 592de0a550
commit 02f437509a
1 changed files with 3 additions and 6 deletions

View File

@ -43,11 +43,8 @@ import axios from 'axios'
function updateSession (t) {
if (sessionStorage.token !== undefined) {
t.session = sessionStorage.token
axios.get('/api/users/auth', {
headers: {
'Authorization': 'Bearer '.concat(t.session)
}
})
axios.defaults.headers.common['Authorization'] = 'Bearer '.concat(sessionStorage.token)
axios.get('/api/users/auth')
.then(
(response) => {
t.loggedUser = response.data
@ -57,7 +54,6 @@ function updateSession (t) {
t.session = null
t.loggedUser = null
sessionStorage.token = undefined
t.$router.push('/')
}
)
}
@ -88,6 +84,7 @@ export default {
logout () {
sessionStorage.token = undefined
updateSession(this)
this.$router.push('/')
},
login (email, password) {