Files
kestrelos/app/plugins/auth.client.js
Madison Grubb b7046dc0e6 initial commit
2026-02-10 23:32:26 -05:00

14 lines
541 B
JavaScript

export default defineNuxtPlugin(() => {
const route = useRoute()
const baseFetch = globalThis.$fetch ?? $fetch
globalThis.$fetch = baseFetch.create({
onResponseError({ response, request }) {
if (response?.status !== 401) return
const url = typeof request === 'string' ? request : request?.url ?? ''
if (!url.startsWith('/')) return
const redirect = (route.fullPath && route.fullPath !== '/' ? route.fullPath : '/')
navigateTo({ path: '/login', query: { redirect } }, { replace: true })
},
})
})