fix(auth): removed auto logout
This commit is contained in:
@@ -27,24 +27,9 @@ export const useApiFetch = <T>(request: string, options: Parameters<typeof $fetc
|
|||||||
const status = err?.statusCode || err?.status || err?.response?.status
|
const status = err?.statusCode || err?.status || err?.response?.status
|
||||||
|
|
||||||
if (status === 401 || status === 403) {
|
if (status === 401 || status === 403) {
|
||||||
try {
|
console.error(`[API] Authentication error (${status})`)
|
||||||
tokenCookie.value = null
|
|
||||||
tokenState.value = null
|
|
||||||
const authUser = useState('auth_user')
|
|
||||||
authUser.value = null
|
|
||||||
|
|
||||||
console.error(`[API] Authentication error (${status}) - token cleared`)
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[API] Error clearing auth state:', e)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
nuxtApp.runWithContext(() => navigateTo('/auth/login'))
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[API] Error navigating to login:', e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ export const useAuth = () => {
|
|||||||
const user = useState<UserContext | null>('auth_user', () => null)
|
const user = useState<UserContext | null>('auth_user', () => null)
|
||||||
const isSyncingUser = useState<boolean>('auth_syncing', () => false)
|
const isSyncingUser = useState<boolean>('auth_syncing', () => false)
|
||||||
const isAuthenticated = computed(() => !!(tokenState.value || token.value))
|
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) => {
|
watch(() => token.value, (newVal) => {
|
||||||
tokenState.value = newVal || null
|
tokenState.value = newVal || null
|
||||||
@@ -46,6 +50,11 @@ export const useAuth = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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)
|
console.error('[Auth] Sync failed, logging out:', error)
|
||||||
logout()
|
logout()
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ export default defineNuxtPlugin(async () => {
|
|||||||
try {
|
try {
|
||||||
await auth.syncUser()
|
await auth.syncUser()
|
||||||
} catch (error) {
|
} 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)
|
console.error('[Auth Plugin] Sync failed:', error)
|
||||||
auth.logout()
|
auth.logout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user