logout page

This commit is contained in:
Ulf Gebhardt 2021-11-19 20:57:01 +01:00
parent 967864d989
commit c057df54cf
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 14 additions and 5 deletions

View File

@ -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()

View File

@ -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'),

View File

@ -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