diff --git a/resources/js/app.js b/resources/js/app.js index ec6fe306..bd0e4266 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -11,10 +11,10 @@ import Create from './views/Create' import Edit from './views/Edit' import { library } from '@fortawesome/fontawesome-svg-core' -import { faPlusCircle, faQrcode, faImage, faTrash, faEdit } from '@fortawesome/free-solid-svg-icons' +import { faPlus, faQrcode, faImage, faTrash, faEdit, faCheck } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' -library.add(faPlusCircle, faQrcode, faImage, faTrash, faEdit); +library.add(faPlus, faQrcode, faImage, faTrash, faEdit, faCheck); Vue.component('font-awesome-icon', FontAwesomeIcon) diff --git a/resources/js/views/Accounts.vue b/resources/js/views/Accounts.vue index 3c2d376e..edb02f64 100644 --- a/resources/js/views/Accounts.vue +++ b/resources/js/views/Accounts.vue @@ -1,10 +1,6 @@ @@ -47,13 +82,16 @@ ShowTwofaccountInModal : false, twofaccount: {}, editMode : false, + token : null, + username : null, } }, mounted(){ - let token = localStorage.getItem('jwt') + this.token = localStorage.getItem('jwt') + this.username = localStorage.getItem('user') axios.defaults.headers.common['Content-Type'] = 'application/json' - axios.defaults.headers.common['Authorization'] = 'Bearer ' + token + axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.token axios.get('api/twofaccounts').then(response => { response.data.forEach((data) => { @@ -79,11 +117,10 @@ }, methods: { getAccount: function (id) { - let token = localStorage.getItem('jwt') let accountId = id axios.defaults.headers.common['Content-Type'] = 'application/json' - axios.defaults.headers.common['Authorization'] = 'Bearer ' + token + axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.token axios.get('api/twofaccounts/' + id).then(response => { @@ -101,16 +138,34 @@ deleteAccount: function (id) { if(confirm("Are you sure you want to delete this account?")) { - let token = localStorage.getItem('jwt') axios.defaults.headers.common['Content-Type'] = 'application/json' - axios.defaults.headers.common['Authorization'] = 'Bearer ' + token + axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.token axios.delete('/api/twofaccounts/' + id).then(response => { this.accounts.splice(this.accounts.findIndex(x => x.id === id), 1); }) } + }, + + logout(evt) { + if(confirm("Are you sure you want to log out?")) { + axios.post('api/logout').then(response => { + + localStorage.removeItem('jwt'); + delete axios.defaults.headers.common['Authorization']; + + this.$router.go('/login'); + }) + .catch(error => { + localStorage.removeItem('jwt'); + delete axios.defaults.headers.common['Authorization']; + + this.$router.go('/login'); + }); + } } + }, beforeRouteEnter (to, from, next) { if ( ! localStorage.getItem('jwt')) { diff --git a/resources/js/views/App.vue b/resources/js/views/App.vue index d319dfc7..333b392a 100644 --- a/resources/js/views/App.vue +++ b/resources/js/views/App.vue @@ -1,38 +1,5 @@