Commit 37c057ea authored by Anton's avatar Anton

Always check session before route change

parent 9ed6188a
Pipeline #19622 passed with stage
in 2 minutes and 16 seconds
......@@ -28,47 +28,38 @@ 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) {
if (process.env.IS_ELECTRON) next()
else {
Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$auth.authenticate()
}
}
else if (to.meta.private) {
if (process.env.IS_ELECTRON) next()
else {
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 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