Commit 40bd5f11 authored by Anton's avatar Anton

Check session before each route change

parent e107ff7d
......@@ -28,44 +28,35 @@ Router.beforeEach((to, from, next) => {
else cb()
}
waitForStore(Router.app, () => {
if (!Router.app.$store.state.auth.user) {
Router.app.$auth.checkSession(Router.app.$store).catch(() => {
if (to.meta.private) {
Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$auth.authenticate()
Router.app.$auth.checkSession(Router.app.$store).catch(() => {
if (to.meta.private) {
Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$auth.authenticate()
}
}).then(result => {
if (result) {
const { user, first } = result
if (first) {
console.debug('Auth0 first login', user)
next({ name: 'users.manage', params: { isFirst: true, redirect: to } })
}
}).then(result => {
if (result) {
const { user, first } = result
if (first) {
console.debug('Auth0 first login', user)
next({ name: 'users.manage', params: { isFirst: true, redirect: to } })
}
else {
if (to.meta.feature) {
if (userHasFeature(Router.app.$store.state.auth.user, to.meta.feature)) next()
else next({ name: 'site.welcome' })
}
next()
else {
if (to.meta.feature) {
if (userHasFeature(Router.app.$store.state.auth.user, to.meta.feature)) next()
else next({ name: 'site.welcome' })
}
next()
}
else if (to.meta.private) {
Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$auth.authenticate()
}
else next()
}).catch(err => {
Router.app.$captureException(err)
Router.app.$auth.logout()
})
}
else {
if (to.meta.feature) {
if (userHasFeature(Router.app.$store.state.auth.user, to.meta.feature)) next()
else next({ name: 'site.welcome' })
}
next()
}
else if (to.meta.private) {
Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$auth.authenticate()
}
else next()
}).catch(err => {
Router.app.$captureException(err)
Router.app.$auth.logout()
})
})
})
......
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