initial commit
This commit is contained in:
13
app/plugins/auth.client.js
Normal file
13
app/plugins/auth.client.js
Normal file
@@ -0,0 +1,13 @@
|
||||
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 })
|
||||
},
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user