fix: logout #286

This commit is contained in:
Daan Wijns 2021-08-29 11:26:13 +02:00
parent d8e2610419
commit 912123098e
3 changed files with 9 additions and 13 deletions

View file

@ -134,7 +134,7 @@ export default {
methods: {
logout() {
this.$store.commit('LOGOUT')
this.$router.push('/login')
this.$router.push({ name: 'login' })
},
toggleSpeed() {
qbit.toggleSpeedLimitsMode()

View file

@ -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) {
@ -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()
})

View file

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