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:
parent
412849b312
commit
734122ad27
4 changed files with 56 additions and 31 deletions
|
|
@ -1,5 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useTheme } from '@/components/theme-provider'
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
|
@ -15,6 +16,7 @@ interface NavigationItem {
|
|||
href: string
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const { theme, setTheme } = useTheme()
|
||||
const isOpen = ref(false)
|
||||
|
|
@ -41,9 +43,10 @@ const openLoginDialog = () => {
|
|||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
await auth.logout()
|
||||
auth.logout()
|
||||
isOpen.value = false
|
||||
// The redirect is now handled in the auth.logout() function
|
||||
// Redirect to login page
|
||||
router.push('/login')
|
||||
} catch (error) {
|
||||
console.error('Logout failed:', error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue