Don't take router decision before session has been fully initialized
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1c1a784aff
commit
1d1aeef5cd
|
@ -259,23 +259,38 @@ const router = new VueRouter({
|
|||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.matched.some(record => record.meta.requiresAuth)) {
|
||||
if (store.getters['user/user_getSession'] == null) {
|
||||
next({
|
||||
path: '/login',
|
||||
params: { nextUrl: to.fullPath }
|
||||
})
|
||||
function routerProceed () {
|
||||
if (to.matched.some(record => record.meta.requiresAuth)) {
|
||||
if (store.getters['user/user_getSession'] == null) {
|
||||
next({
|
||||
path: '/login',
|
||||
params: { nextUrl: to.fullPath }
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else if (to.matched.some(record => record.meta.guest)) {
|
||||
if (store.getters['user/user_getSession'] == null) {
|
||||
next()
|
||||
} else {
|
||||
next({ name: 'home' })
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else if (to.matched.some(record => record.meta.guest)) {
|
||||
if (store.getters['user/user_getSession'] == null) {
|
||||
next()
|
||||
} else {
|
||||
next({ name: 'home' })
|
||||
}
|
||||
}
|
||||
|
||||
if (!store.state.user.initialized) {
|
||||
store.watch(
|
||||
(state) => state.user.initialized,
|
||||
(value) => {
|
||||
if (value) {
|
||||
routerProceed()
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
next()
|
||||
routerProceed()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -36,12 +36,14 @@ export default {
|
|||
namespaced: true,
|
||||
|
||||
state: {
|
||||
initialized: false,
|
||||
session: null
|
||||
},
|
||||
|
||||
getters: {
|
||||
user_getSession: state => state.session,
|
||||
user_getSettings: state => state.session ? state.session.settings : null,
|
||||
user_initialized: state => state.initialized,
|
||||
user_isLogged: state => state.session != null
|
||||
},
|
||||
|
||||
|
@ -114,17 +116,20 @@ export default {
|
|||
Vue.set(state, 'session', null)
|
||||
sessionStorage.clear()
|
||||
}
|
||||
Vue.set(state, 'initialized', true)
|
||||
}
|
||||
},
|
||||
|
||||
auth_success (state, session) {
|
||||
Vue.set(state, 'session', session)
|
||||
sessionStorage.loggedUser = JSON.stringify(session)
|
||||
Vue.set(state, 'initialized', true)
|
||||
},
|
||||
|
||||
logout (state) {
|
||||
Vue.set(state, 'session', null)
|
||||
sessionStorage.clear()
|
||||
Vue.set(state, 'initialized', true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user