Files
kestrelos/app/plugins/auth.client.js
Madison Grubb 1668ec4230
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
heavily simplify server and app content. unify styling
2026-02-13 23:36:17 -05:00

14 lines
550 B
JavaScript

/** Wraps $fetch to redirect to /login on 401 for same-origin requests. */
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
navigateTo({ path: '/login', query: { redirect: route.fullPath || '/' } }, { replace: true })
},
})
})