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,4 @@
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { lnbitsAPI, type User, type LoginCredentials, type RegisterData } from '@/lib/api/lnbits'
const currentUser = ref<User | null>(null)
@ -7,7 +6,6 @@ const isLoading = ref(false)
const error = ref<string | null>(null)
export function useAuth() {
const router = useRouter()
const isAuthenticated = computed(() => !!currentUser.value)
/**
@ -77,16 +75,10 @@ export function useAuth() {
* Logout and clear user data
*/
async function logout(): Promise<void> {
try {
await lnbitsAPI.logout()
} catch (err) {
console.error('Logout error:', err)
} finally {
currentUser.value = null
error.value = null
// Redirect to login page after logout
router.push('/login')
}
// Clear local state
lnbitsAPI.logout()
currentUser.value = null
error.value = null
}
/**