Skip to content

Commit

Permalink
fix: redirect from login page if authenticated
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Sep 24, 2024
1 parent 74890da commit c4b7f28
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ import Icons from '@/views/Icons.vue'
Vue.use(VueRouter)

const ifAuthenticated = (to: Route, from: Route, next: NavigationGuardNext<Vue>) => {
if (
const isAuthenticated = (
router.app.$store.getters['auth/getAuthenticated'] ||
!router.app.$store.state.socket.apiConnected
) {
next()
)
const isLoginPage = to.path === '/login'

if (isAuthenticated) {
if (isLoginPage) {
next('/')
} else {
next()
}
} else {
next('/login')
if (isLoginPage) {
next()
} else {
next('/login')
}
}
}

Expand Down Expand Up @@ -140,6 +151,7 @@ const routes: Array<RouteConfig> = [
path: '/login',
name: 'Login',
component: Login,
...defaultRouteConfig,
meta: {
fillHeight: true
}
Expand Down

0 comments on commit c4b7f28

Please sign in to comment.