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) => { ...@@ -28,47 +28,38 @@ Router.beforeEach((to, from, next) => {
else cb() else cb()
} }
waitForStore(Router.app, () => { waitForStore(Router.app, () => {
if (!Router.app.$store.state.auth.user) { Router.app.$auth.checkSession(Router.app.$store).catch(() => {
Router.app.$auth.checkSession(Router.app.$store).catch(() => { if (to.meta.private) {
if (to.meta.private) { Router.app.$store.commit('auth/setRedirect', to.fullPath)
Router.app.$store.commit('auth/setRedirect', to.fullPath) Router.app.$auth.authenticate()
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 => { else {
if (result) { if (to.meta.feature) {
const { user, first } = result if (userHasFeature(Router.app.$store.state.auth.user, to.meta.feature)) next()
if (first) { else next({ name: 'site.welcome' })
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()
} }
next()
} }
else if (to.meta.private) { }
if (process.env.IS_ELECTRON) next() else if (to.meta.private) {
else { if (process.env.IS_ELECTRON) next()
Router.app.$store.commit('auth/setRedirect', to.fullPath) else {
Router.app.$auth.authenticate() 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