N
Nuxt7mo ago
stefanpeev

Hey guys, how do you set a token in your headers in nuxt3.

I am trying to set my django backend jwt token in my request headers after i fetch it.Right now im getting it from the cookies and setting in my fetches everytime.
1 Reply
Rdd0u
Rdd0u7mo ago
That would be
useFetch('url', {
headers: {
"Authorization" : 'token'
}
})
useFetch('url', {
headers: {
"Authorization" : 'token'
}
})
See the docs here: https://nuxt.com/docs/api/composables/use-fetch#type To keep it DRY, I would suggest creating a customFetch composable that will bake that behaviour in. Check this: https://nuxt.com/docs/examples/advanced/use-custom-fetch-composable
Nuxt
Use Custom Fetch Composable · Nuxt Examples
This example shows a convenient wrapper for the useFetch composable from nuxt. It allows you to customize the fetch request with default values and user authentication token.
Nuxt
useFetch · Nuxt Composables
Fetch data from an API endpoint with an SSR-friendly composable.
Want results from more Discord servers?
Add your server