Files
kestrelos/app/plugins/auth.client.js
Keli Grubb 17f28401ba
All checks were successful
ci/woodpecker/push/push Pipeline was successful
minor: heavily simplify server and app content. unify styling (#4)
Co-authored-by: Madison Grubb <madison@elastiflow.com>
Reviewed-on: #4
2026-02-14 04:52:18 +00: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 })
},
})
})