You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
551 B
TypeScript

import type { UseFetchOptions } from 'nuxt/app'
const useCustomFetch = async <T>(
path: string,
options: UseFetchOptions<T> = {}
) => {
let headers: any = {}
const token = useCookie('XSRF-TOKEN')
if (token.value) {
headers['X-XSRF-TOKEN'] = token.value as string
}
return useFetch('http://localhost:8080' + path, {
credentials: 'include',
watch: false,
...options,
headers: {
...headers,
...options?.headers,
},
})
}
export { useCustomFetch }