Skip to content

Commit d34f014

Browse files
authored
Merge branch 'main' into patch-1
2 parents 4a06d8d + 20b3c77 commit d34f014

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.changesets/11718.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- fix(dbAuth): Don't use Multi Value Headers on Vercel (#11718) by @Tobbe
2+
3+
Fixes a regression regarding dbAuth on Vercel introduced in RW 8

packages/auth-providers/dbAuth/api/src/shared.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,18 @@ export function getDbAuthResponseBuilder(
295295
const setCookieHeaders = response.headers?.getSetCookie() || []
296296

297297
if (setCookieHeaders.length > 0) {
298-
if ('multiValueHeaders' in event) {
298+
delete headers['set-cookie']
299+
delete headers['Set-Cookie']
300+
301+
if (supportsMultiValueHeaders(event)) {
299302
dbAuthResponse.multiValueHeaders = {
303+
// Netlify wants 'Set-Cookie' headers to be capitalized
304+
// https://github.com/redwoodjs/redwood/pull/10889
300305
'Set-Cookie': setCookieHeaders,
301306
}
302-
delete headers['set-cookie']
303307
} else {
308+
// If we do this for Netlify the lambda function will throw an error
309+
// https://github.com/redwoodjs/redwood/pull/10889
304310
headers['set-cookie'] = setCookieHeaders
305311
}
306312
}
@@ -309,6 +315,16 @@ export function getDbAuthResponseBuilder(
309315
}
310316
}
311317

318+
// `'multiValueHeaders' in event` is true for both Netlify and Vercel
319+
// but only Netlify actually supports it. Vercel will just ignore it
320+
// https://github.com/vercel/vercel/issues/7820
321+
function supportsMultiValueHeaders(event: APIGatewayProxyEvent | Request) {
322+
return (
323+
'multiValueHeaders' in event &&
324+
(!event.headers || !('x-vercel-id' in event.headers))
325+
)
326+
}
327+
312328
export const extractHashingOptions = (text: string): ScryptOptions => {
313329
const [_hash, ...options] = text.split('|')
314330

0 commit comments

Comments
 (0)