refactor: Simplify logout process and enhance routing in authentication components

- Remove unnecessary async handling in logout functions across UserProfile.vue and Navbar.vue.
- Integrate `useRouter` for consistent redirection to the login page after logout.
- Update `logout` method in useAuth.ts to clear local state without an API call.
This commit is contained in:
padreug 2025-07-30 00:23:36 +02:00
parent 412849b312
commit 734122ad27
4 changed files with 56 additions and 31 deletions

View file

@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
@ -7,15 +8,13 @@ import { User, LogOut, Settings } from 'lucide-vue-next'
import { auth } from '@/composables/useAuth'
import { toast } from 'vue-sonner'
const router = useRouter()
const userDisplay = computed(() => auth.userDisplay.value)
async function handleLogout() {
try {
await auth.logout()
toast.success('Logged out successfully')
} catch (error) {
toast.error('Failed to logout')
}
function handleLogout() {
auth.logout()
toast.success('Logged out successfully')
router.push('/login')
}
</script>