Comments (5)
@danekslama this is probably #27660
from nuxt.js.
When using a custom fetch, Nuxt does not perform 'internal' fetches or pass on headers automatically - you will need to do this manually if that's the behaviour you want.
from nuxt.js.
@danielroe we have a similar issue. It seems that cookies are not somehow reactive in the newest version. It was working before the update to 3.12.2.
Tested on 3.11.2 and working correctly.
from nuxt.js.
How can I have a custom fetch but with all the behavior as before? The docs didnt say anything about the downsides of missing functionality when using custom fetch. Is there any example that has custom fetch but with everything as before?
I just want to have an interceptor that redirects if any response is 401 but this seems to be the most complicated thing ever :(
from nuxt.js.
@MickL The docs are not very clear, but you need to recreate the functionality you need:
https://nuxt.com/docs/getting-started/data-fetching#passing-headers-and-cookies
In practice, for cookies, you need something akin to:
export const myFetch = $fetch.create({
async onRequest(ctx) {
if (import.meta.server) {
// Forward cookies to the target
ctx.options.headers = useRequestHeaders(['cookie'])
// Save event for later, we need it to forward response cookies
;(ctx as any).event = useRequestEvent()
}
},
async onResponse(ctx) {
if (import.meta.server && ctx.response.headers.get('set-cookie')) {
// Forward response cookies to the client
const cookieHeader = ctx.response.headers.get('set-cookie')!
appendResponseHeader((ctx as any).event, 'set-cookie', cookieHeader)
}
},
})
After investigating your reproduction, it does not forward any cookie on SSR. You must have been setting it via client-side request in your tests:
Reload page 1: Cookie is not set
Navigate to page 2, back to page 1: Cookie is set
from nuxt.js.
Related Issues (20)
- TAR_BAD_ARCHIVE giget HOT 1
- RangeError: [nuxt:components:imports] path should be a `path.relative()`d string,
- Incrementing/Repeated Routes (?) HOT 3
- Can't call the same composable that using a composable that require nuxt instance in same function HOT 3
- npm run genreate first render is cache data
- Cannot read properties of null (reading 'parentNode') when navigate from page HOT 11
- Environment Variables logging to console but aren't able to be used HOT 4
- On redirection with NuxtLink pageLayout is not set that is defined in definePageMeta HOT 1
- module get `modulepreload` despite dynamic import HOT 1
- Can't seem to access studio configuration data in application HOT 4
- npm run genreate first render is cache data
- The `jsx` doesn't work after being compiled in Nuxt? HOT 2
- How client component use data from server component? HOT 1
- When starting up in the development environment, more information streams should be displayed HOT 2
- Better Error Messages when Using Layers HOT 2
- "Unexpected token ';'" error when running the build. HOT 3
- propsDestructure no longer working HOT 1
- nuxi always using default npm registry
- ERROR Error: Failed to installing nuxt : Invalid URL
- theme-color meta tags are incorrectly deduped HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.