From a92f5b69a324476609454d12a301841e499a8dfe Mon Sep 17 00:00:00 2001 From: ltuffery <123221865+ltuffery@users.noreply.github.com> Date: Wed, 14 Oct 2026 10:19:12 +0200 Subject: [PATCH] add logout btn in one click --- frontend/src/components/layout/NavBar.vue | 51 ++++++++++++++++------- frontend/src/composable/useAuth.ts | 8 ++-- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/layout/NavBar.vue b/frontend/src/components/layout/NavBar.vue index 9e49d1b9..d0047d4a 100644 --- a/frontend/src/components/layout/NavBar.vue +++ b/frontend/src/components/layout/NavBar.vue @@ -1,13 +1,13 @@ @@ -37,21 +41,31 @@ const goTo = (path: string) => router.push(path) - + + + + + {{ item.label }} + + + logout()" > - - {{ item.label }} + + Logout @@ -77,6 +91,13 @@ const goTo = (path: string) => router.push(path) /> {{ item.label }} + logout()" + class="flex flex-col items-center justify-center gap-1 flex-1 h-full text-xs transition-colors text-muted-foreground" + > + + Logout + diff --git a/frontend/src/composable/useAuth.ts b/frontend/src/composable/useAuth.ts index c1645ee5..c606c437 100644 --- a/frontend/src/composable/useAuth.ts +++ b/frontend/src/composable/useAuth.ts @@ -1,6 +1,6 @@ import { ref } from 'vue' import { authApi, type LoginResponse, type RegisterCredentials } from '@/api/auth' -import { getSocket } from '@/plugins/socket' +import { disconnectSocket, getSocket } from '@/plugins/socket' import router from '@/router' import { useAuthStore } from '@/store/useAuthStore' @@ -99,12 +99,12 @@ export function useAuth() { useAuthStore().clearSession() - getSocket().close() + disconnectSocket() } - const disconnect = (): void => { + const disconnect = async (): Promise => { logout() - router.push({ name: 'home' }).then(r => {}) + await router.push({ name: 'auth' }) } const forgotPassword = async (email: string): Promise => {