QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.28k stars 59 forks source link

fix(next-international): preserve cookies in the middleware #271

Closed Yovach closed 11 months ago

Yovach commented 11 months ago

Fixes #212

The response from NextResponse.next and NextResponse.redirect doesn't contains any cookies except the Next-Locale set by the middleware.

At first, I wanted to clone the headers but this added a lot of elements that were not included in the basic Server Actions

EDIT: I've just noticed that the "Set-Cookie" header was defined for each request, which isn't great.

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-international ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 27, 2023 8:28pm
Yovach commented 11 months ago

I checked and it shouldn't be a problem.

We can use the init parameter of NextResponse.redirect and NextResponse.rewrite but it'll pass all headers

Yovach commented 11 months ago

The fact that Set-Cookie is set on each request is probably an issue because it'll break sites that are using Cookie parameters.

I just noticed that this also removes things like "HttpOnly" and "Secure" so the PR doesn't seems to be ready yet :/

Yovach commented 11 months ago

With my latest commit, the problem seems to have been solved as the Next-Locale cookie is only applied if necessary. I've tried this when we change the locale by url (http://localhost:3000/en => http://localhost:3000/fr) and it doesn't clear my current cookies.