fix logout action
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<header class="header">
|
||||
<div class="container wrapper">
|
||||
<div class="navmenu-container">
|
||||
<NavMenu @logout="logout" />
|
||||
<NavMenu @handle-logout="handleLogout" />
|
||||
</div>
|
||||
<!-- isAdmin: {{ isAdmin }} <br>
|
||||
isAuthenticated: {{ isAuthenticated }} <br> -->
|
||||
@@ -71,7 +71,6 @@
|
||||
import { mapActions } from 'pinia'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
export default {
|
||||
|
||||
setup() {
|
||||
const auth = useAuthStore();
|
||||
return {
|
||||
@@ -89,10 +88,9 @@ export default {
|
||||
return this.auth.getName
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
...mapActions('auth', ['logout']),
|
||||
async logout() {
|
||||
...mapActions(useAuthStore, ['logout']),
|
||||
async handleLogout() {
|
||||
try {
|
||||
await this.logout()
|
||||
this.$router.push('/login')
|
||||
|
||||
@@ -13,12 +13,13 @@
|
||||
to="/editar/productos/importar"
|
||||
>Importar</NuxtLink
|
||||
>
|
||||
<NuxtLink to="/" @click="logout" >Cerrar sesión</NuxtLink>
|
||||
<NuxtLink to="/" @click="handleLogout" >Cerrar sesión</NuxtLink>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { mapActions } from 'pinia'
|
||||
export default {
|
||||
setup() {
|
||||
const auth = useAuthStore();
|
||||
@@ -35,8 +36,14 @@ export default {
|
||||
await this.checkIfCoopValidated()
|
||||
},
|
||||
methods: {
|
||||
async logout() {
|
||||
await this.auth.logout()
|
||||
...mapActions(useAuthStore, ['logout']),
|
||||
async handleLogout() {
|
||||
try {
|
||||
await this.logout()
|
||||
this.$router.push('/')
|
||||
} catch (error) {
|
||||
console.error('Error logging out:', error)
|
||||
}
|
||||
},
|
||||
async checkIfCoopValidated() {
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<template>
|
||||
<div class="navsearch_container container-fluid">
|
||||
<NuxtLink to="/editar/perfil">Mi perfil</NuxtLink>
|
||||
<NuxtLink to="/" @click="logout" >Cerrar sesión</NuxtLink>
|
||||
<NuxtLink to="/" @click="handleLogout" >Cerrar sesión</NuxtLink>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { mapActions } from 'pinia'
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const auth = useAuthStore();
|
||||
@@ -15,8 +17,14 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async logout() {
|
||||
await this.auth.logout()
|
||||
...mapActions(useAuthStore, ['logout']),
|
||||
async handleLogout() {
|
||||
try {
|
||||
await this.logout()
|
||||
this.$router.push('/')
|
||||
} catch (error) {
|
||||
console.error('Error logging out:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<span class="section-text login">Importar</span>
|
||||
</li>
|
||||
</NuxtLink>
|
||||
<NuxtLink v-if="isAuthenticated" @click="logout" to="/">
|
||||
<NuxtLink v-if="isAuthenticated" @click="handleLogout" to="/">
|
||||
<li class="section" @click="isMenuOpen = !isMenuOpen">
|
||||
<img
|
||||
class="section-img"
|
||||
@@ -145,6 +145,7 @@ import { mapActions } from 'pinia'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
export default {
|
||||
emits: ['handleLogout'],
|
||||
setup() {
|
||||
const auth = useAuthStore();
|
||||
return {
|
||||
@@ -165,11 +166,11 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapActions('auth', ['logout']),
|
||||
async logout() {
|
||||
...mapActions(useAuthStore, ['logout']),
|
||||
async handleLogout() {
|
||||
this.isMenuOpen = false
|
||||
this.$emit('logout')
|
||||
await this.logout()
|
||||
this.$emit('handleLogout')
|
||||
//await this.logout()
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user