fix: auth redirects and routing context issues
This commit is contained in:
@@ -2,7 +2,8 @@ import { defu } from 'defu'
|
||||
|
||||
export const useApiFetch = <T>(request: string, options: Parameters<typeof $fetch>[1] = {}) => {
|
||||
const config = useRuntimeConfig()
|
||||
const tokenCookie = useCookie('auth_token')
|
||||
const nuxtApp = useNuxtApp()
|
||||
const tokenCookie = useCookie('auth_token', { path: '/' })
|
||||
const tokenState = useState<string | null>('auth_token_state')
|
||||
|
||||
const tokenValue = tokenState.value ?? tokenCookie.value
|
||||
@@ -38,7 +39,7 @@ export const useApiFetch = <T>(request: string, options: Parameters<typeof $fetc
|
||||
}
|
||||
|
||||
try {
|
||||
navigateTo('/auth/login')
|
||||
nuxtApp.runWithContext(() => navigateTo('/auth/login'))
|
||||
} catch (e) {
|
||||
console.error('[API] Error navigating to login:', e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user