Commit 47bd40b3 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

axios logout

parent 63274c7a
...@@ -43,22 +43,32 @@ ...@@ -43,22 +43,32 @@
export default { export default {
methods: { methods: {
logout () { async logout () {
fetch('http://127.0.0.1:8000/api/logout', { try {
method: 'POST', const resp = await this.$axios.post('/logout', {
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
token: this.$auth.$storage.getUniversal('token') token: this.$auth.$storage.getUniversal('token')
},
{
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
}
})
if (resp.status == '200') {
this.$toast.success('Successfully authenticated', {
duration: 2000
})
this.$router.push('/login')
localStorage.setItem('token', '')
this.$auth.$storage.setUniversal('loggedIn', 'false')
this.$auth.$storage.setUniversal('token', '')
this.$auth.$storage.setUniversal('userName', '')
}
} catch (e) {
this.$toast.error('ERR !', {
duration: 2000
}) })
}) }
localStorage.setItem('token', '')
this.$auth.$storage.setUniversal('loggedIn', 'false')
this.$auth.$storage.setUniversal('token', '')
this.$auth.$storage.setUniversal('userName', '')
this.$router.push('/login')
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment