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
|
|
@ -50,14 +50,50 @@ class LnbitsAPI {
|
|||
(headers as Record<string, string>)['Authorization'] = `Bearer ${this.accessToken}`
|
||||
}
|
||||
|
||||
// Debug logging
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.log('LNBits API Request:', {
|
||||
url,
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers,
|
||||
body: options.body
|
||||
})
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers,
|
||||
})
|
||||
|
||||
// Debug logging
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.log('LNBits API Response:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
url: response.url
|
||||
})
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}))
|
||||
throw new Error(errorData.detail || `HTTP ${response.status}: ${response.statusText}`)
|
||||
let errorMessage = `HTTP ${response.status}: ${response.statusText}`
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
errorMessage = errorData.detail || errorData.message || errorMessage
|
||||
} catch {
|
||||
// If we can't parse JSON, use the default error message
|
||||
}
|
||||
|
||||
// Debug logging for errors
|
||||
if (import.meta.env.VITE_LNBITS_DEBUG === 'true') {
|
||||
console.error('LNBits API Error:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
url: response.url,
|
||||
error: errorMessage
|
||||
})
|
||||
}
|
||||
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
|
|
@ -88,14 +124,9 @@ class LnbitsAPI {
|
|||
}
|
||||
|
||||
async logout(): Promise<void> {
|
||||
try {
|
||||
await this.request('/auth/logout', {
|
||||
method: 'POST',
|
||||
})
|
||||
} finally {
|
||||
this.accessToken = null
|
||||
removeAuthToken()
|
||||
}
|
||||
// Just clear local state - no API call needed for logout
|
||||
this.accessToken = null
|
||||
removeAuthToken()
|
||||
}
|
||||
|
||||
async getCurrentUser(): Promise<User> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue