Navigation Menu

Skip to content

Commit

Permalink
fix: logout #286
Browse files Browse the repository at this point in the history
  • Loading branch information
WDaan committed Aug 29, 2021
1 parent d8e2610 commit 9121230
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/Navbar/NavbarActions.vue
Expand Up @@ -134,7 +134,7 @@ export default {
methods: {
logout() {
this.$store.commit('LOGOUT')
this.$router.push('/login')
this.$router.push({ name: 'login' })
},
toggleSpeed() {
qbit.toggleSpeedLimitsMode()
Expand Down
13 changes: 1 addition & 12 deletions src/router.js
Expand Up @@ -25,19 +25,14 @@ const router = new Router({
name: 'login',
component: Login,
meta: {
public: true, // Allow access to even if not logged in
onlyWhenLoggedOut: true
public: true // Allow access to even if not logged in }
}
}

]
})

router.beforeEach(async (to, from, next) => {
const isPublic = to.matched.some(record => record.meta.public)
const onlyWhenLoggedOut = to.matched.some(
record => record.meta.onlyWhenLoggedOut
)
const authenticated = isAuthenticated()

if (!isPublic && !authenticated) {
Expand All @@ -48,12 +43,6 @@ router.beforeEach(async (to, from, next) => {
})
}

// Do not allow user to visit login page or register page
// if they are logged in
if (authenticated && onlyWhenLoggedOut) {
return next('/')
}

next()
})

Expand Down
7 changes: 7 additions & 0 deletions src/views/Login.vue
Expand Up @@ -48,6 +48,8 @@

<script>
import { mdiLock, mdiAccount } from '@mdi/js'
import { isAuthenticated } from '@/services/auth.js'
export default {
name: 'Login',
data() {
Expand All @@ -58,6 +60,11 @@ export default {
mdiLock, mdiAccount
}
},
mounted() {
if (isAuthenticated()) {
this.$router.push('/')
}
},
methods: {
async Login() {
const authenticated = await this.$store.dispatch('LOGIN', {
Expand Down

0 comments on commit 9121230

Please sign in to comment.