Comments (6)
Correct, this is now confirmed not to be a bug in edge-runtime
. I forwarded this to the responsible Vercel team. (Vercel itself does not use the edge-runtime
package, but the intention is that the implementation is identical).
next-auth
will have to update to getSetCookie
as well, and once it's fixed on Vercel, everything should work as expected.
I'm closing this issue then. Thanks!
from edge-runtime.
@balazsorban44 Is there anywhere that interested parties can follow along with the progress of the bug fix (a public issue, or a commitment that an update will be shared somewhere)?
from edge-runtime.
Hi, from the looks of it, I believe that this works as-per spec:
Here, .get()
will always return a string, see https://fetch.spec.whatwg.org/#dom-headers-get
.getSetCookie()
will return an array instead, and should be used when trying to access a list of set-cookie
headers. 🤔
splitCookiesString
is essentially doing the same as .getSetCookie()
, but is not built into the platform, while .getSetCookie()
is a web standard now, and should be preferred. See https://fetch.spec.whatwg.org/#dom-headers-getsetcookie
from edge-runtime.
The spec also says that .set()
:
Replaces the value of the first header whose name is name with value and removes any remaining headers whose name is name.
So you might need to do the for-each loop as in https://github.com/edenstrom/vercel-set-cookie-header/blob/c91a21a0e90c282b2144b84f7524902a2c9ea853/src/app/api/parseEdge/route.ts#L21 instead of https://github.com/edenstrom/vercel-set-cookie-header/blob/c91a21a0e90c282b2144b84f7524902a2c9ea853/src/app/api/edge/route.ts#L18
Combining this info, I think the correct way to write this would be:
import { NextRequest, NextResponse } from "next/server"
export const runtime = "edge"
export const GET = async (req: NextRequest) => {
const url = `${req.nextUrl.origin}/api/cookie`
const sessionResponse = await fetch(url, { credentials: "include" })
const setCookies = sessionResponse.headers.getSetCookie() ?? []
const response = NextResponse.json({
route: "success. Returns multiple Set-Cookie headers"
})
for (const cookie in setCookies) {
response.cookies.set("set-cookie", cookie)
}
return response
}
from edge-runtime.
Related microsoft/TypeScript#55270
from edge-runtime.
The spec also says that
.set()
:Replaces the value of the first header whose name is name with value and removes any remaining headers whose name is name.
So you might need to do the for-each loop as in edenstrom/vercel-set-cookie-header@
c91a21a
/src/app/api/parseEdge/route.ts#L21 instead of edenstrom/vercel-set-cookie-header@c91a21a
/src/app/api/edge/route.ts#L18Combining this info, I think the correct way to write this would be:
import { NextRequest, NextResponse } from "next/server" export const runtime = "edge" export const GET = async (req: NextRequest) => { const url = `${req.nextUrl.origin}/api/cookie` const sessionResponse = await fetch(url, { credentials: "include" }) const setCookies = sessionResponse.headers.getSetCookie() ?? [] const response = NextResponse.json({ route: "success. Returns multiple Set-Cookie headers" }) for (const cookie in setCookies) { response.cookies.set("set-cookie", cookie) } return response }
Hey! Yeah, you're right that it's according to spec. Just a weird use-case when it's server-to-server. 😅
Sadly there's no support for .getSetCookie
in Vercel Edge Runtime yet. I've added a new route + button for that in the reproduction above. Returns 500 with the error TypeError: K.headers.getSetCookie is not a function
. Works locally, but not deployed. (I guess the local version is a Node-based wrapper?)
Related:
The code in the edge-compatible next-auth
should probably handle this use-case as well then? Wait for .getSetCookie
or go with @edge-runtime/cookies
?
from edge-runtime.
Related Issues (20)
- Expose cookie serialization functions. HOT 1
- Include a key in process.versions for detecting edge runtime HOT 2
- Support `has` in ResponseCookies
- Primitives: event-target-shim causes issues w/ edge-runtime running on top of node HOT 3
- drop node16 support
- Proxying primitive instances return anonymous `toString()` return functions
- Why cannot my `fetch` API work in edge function? HOT 4
- 🙏`fetch` api doesn't work in edge function HOT 4
- Which functions and APIs advance the value returned by `Date.now`? HOT 3
- Polyfill for btoa inconsistent with WebApi / Node HOT 5
- drop node18 support
- Response.redirect() fails to parse some URLs in production which parse successfully in local runtime HOT 2
- `@edge-runtime/node-utils` can't start example server from docs using `primitives` (node v18.18.2) Headers2 is not a constructor HOT 1
- Secure Cookies can't be deleted from Responses
- CompressionStream / DecompressionStream support?
- failing on buffer
- Does Edge Runtime use alternative vm instead of node:vm? HOT 3
- crypto.subtle.importKey does not accept ArrayBuffer (ArrayBuffer.prototype mismatch) HOT 1
- Cannot use @edge-runtime/jest-environment
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 edge-runtime.