From 48f0f65dc1641ec5e4b35faa18c227fce5f10b77 Mon Sep 17 00:00:00 2001 From: gabdevele Date: Mon, 15 Jun 2026 11:47:40 +0200 Subject: [PATCH] fix(auth): removed auto logout --- app/composables/useApiFetch.ts | 19 ++----------------- app/composables/useAuth.ts | 9 +++++++++ app/plugins/auth.client.ts | 8 +++++++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/composables/useApiFetch.ts b/app/composables/useApiFetch.ts index be947a2..b273ac2 100644 --- a/app/composables/useApiFetch.ts +++ b/app/composables/useApiFetch.ts @@ -27,24 +27,9 @@ export const useApiFetch = (request: string, options: Parameters navigateTo('/auth/login')) - } catch (e) { - console.error('[API] Error navigating to login:', e) - } + console.error(`[API] Authentication error (${status})`) } throw err }) -} \ No newline at end of file +} diff --git a/app/composables/useAuth.ts b/app/composables/useAuth.ts index 37e510d..a6dc2da 100644 --- a/app/composables/useAuth.ts +++ b/app/composables/useAuth.ts @@ -24,6 +24,10 @@ export const useAuth = () => { const user = useState('auth_user', () => null) const isSyncingUser = useState('auth_syncing', () => false) const isAuthenticated = computed(() => !!(tokenState.value || token.value)) + const isAuthStatusError = (error: any) => { + const status = error?.statusCode || error?.status || error?.response?.status + return status === 401 || status === 403 + } watch(() => token.value, (newVal) => { tokenState.value = newVal || null @@ -46,6 +50,11 @@ export const useAuth = () => { } } } catch (error) { + if (isAuthStatusError(error)) { + console.error('[Auth] Sync failed with authentication error, keeping session state:', error) + return + } + console.error('[Auth] Sync failed, logging out:', error) logout() } finally { diff --git a/app/plugins/auth.client.ts b/app/plugins/auth.client.ts index 043a200..540720a 100644 --- a/app/plugins/auth.client.ts +++ b/app/plugins/auth.client.ts @@ -5,9 +5,15 @@ export default defineNuxtPlugin(async () => { try { await auth.syncUser() } catch (error) { + const status = (error as any)?.statusCode || (error as any)?.status || (error as any)?.response?.status + + if (status === 401 || status === 403) { + console.error('[Auth Plugin] Sync failed with authentication error, keeping session state:', error) + return + } + console.error('[Auth Plugin] Sync failed:', error) auth.logout() } } }) -