#fetch options

3 messages · Page 1 of 1 (latest)

young oak
#

how to set authorization header in useFetch options? i am using external api and i need to send token for every request. do you know of a interceptor example that I can do this?

smoky sparrow
#

Hey, you can check the TypeScript types to see which options the useFetch has.

For headers, it's

const { data } = await useFetch(() => `https://jsonplaceholder.typicode.com/todos/1`, {
  headers: new Headers({
    'authorization': 'Bearer 123',
  }),
})
#

You can create yourself a composable that wraps useFetch and then intercept it by always adding that option besides the others