diff --git a/admin/src/router/guards.js b/admin/src/router/guards.js index d6eeda927..6207f443e 100644 --- a/admin/src/router/guards.js +++ b/admin/src/router/guards.js @@ -1,12 +1,8 @@ const addNavigationGuards = (router, store) => { // store token on authenticate router.beforeEach((to, from, next) => { - console.log('token', to.path, from.path, to.query) - // handle authentication if (to.path === '/authenticate' && to.query.token) { - console.log('token', to.query.token, to) store.commit('token',to.query.token) - // to.query = {} next({path: '/'}) } else { next() @@ -17,7 +13,7 @@ const addNavigationGuards = (router, store) => { router.beforeEach((to, from, next) => { console.log('protect', to.path, from.path) // handle authentication - if (!store.state.token && to.path !== '/not-found') { + if (!store.state.token && to.path !== '/not-found' && to.path !== '/logout') { next({ path: '/not-found' }) } else { next() diff --git a/admin/src/router/routes.js b/admin/src/router/routes.js index 31008824d..72e7b1ac5 100644 --- a/admin/src/router/routes.js +++ b/admin/src/router/routes.js @@ -6,6 +6,11 @@ const routes = [ path: '/', component: () => import('@/pages/Overview.vue'), }, + { + // TODO: Implement a "You are logged out"-Page + path: '/logout', + component: () => import('@/components/NotFoundPage.vue'), + }, { path: '/user', component: () => import('@/pages/UserSearch.vue'), diff --git a/admin/src/store/store.js b/admin/src/store/store.js index b3f94b677..544967d6e 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -19,6 +19,13 @@ export const mutations = { } } +export const actions = { + logout: ({ commit, state }) => { + commit('token', null) + localStorage.clear() + }, +} + const store = new Vuex.Store({ plugins: [ createPersistedState({ @@ -32,6 +39,7 @@ const store = new Vuex.Store({ }, // Syncronous mutation of the state mutations, + actions, }) export default store