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', {
token: this.$auth.$storage.getUniversal('token')
},
{
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
accept: 'application/json' accept: 'application/json'
}, }
body: JSON.stringify({
token: this.$auth.$storage.getUniversal('token')
}) })
if (resp.status == '200') {
this.$toast.success('Successfully authenticated', {
duration: 2000
}) })
this.$router.push('/login')
localStorage.setItem('token', '') localStorage.setItem('token', '')
this.$auth.$storage.setUniversal('loggedIn', 'false') this.$auth.$storage.setUniversal('loggedIn', 'false')
this.$auth.$storage.setUniversal('token', '') this.$auth.$storage.setUniversal('token', '')
this.$auth.$storage.setUniversal('userName', '') this.$auth.$storage.setUniversal('userName', '')
this.$router.push('/login') }
} catch (e) {
this.$toast.error('ERR !', {
duration: 2000
})
}
} }
} }
} }
......
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