Skip to content

Commit

Permalink
fix(dbAuth): Don't use Multi Value Headers on Vercel (#11718)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored and Josh-Walker-GM committed Nov 14, 2024
1 parent 96fc9a6 commit b6e6f1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changesets/11718.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix(dbAuth): Don't use Multi Value Headers on Vercel (#11718) by @Tobbe

Fixes a regression regarding dbAuth on Vercel introduced in RW 8
20 changes: 18 additions & 2 deletions packages/auth-providers/dbAuth/api/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,18 @@ export function getDbAuthResponseBuilder(
const setCookieHeaders = response.headers?.getSetCookie() || []

if (setCookieHeaders.length > 0) {
if ('multiValueHeaders' in event) {
delete headers['set-cookie']
delete headers['Set-Cookie']

if (supportsMultiValueHeaders(event)) {
dbAuthResponse.multiValueHeaders = {
// Netlify wants 'Set-Cookie' headers to be capitalized
// https://github.com/redwoodjs/redwood/pull/10889
'Set-Cookie': setCookieHeaders,
}
delete headers['set-cookie']
} else {
// If we do this for Netlify the lambda function will throw an error
// https://github.com/redwoodjs/redwood/pull/10889
headers['set-cookie'] = setCookieHeaders
}
}
Expand All @@ -309,6 +315,16 @@ export function getDbAuthResponseBuilder(
}
}

// `'multiValueHeaders' in event` is true for both Netlify and Vercel
// but only Netlify actually supports it. Vercel will just ignore it
// https://github.com/vercel/vercel/issues/7820
function supportsMultiValueHeaders(event: APIGatewayProxyEvent | Request) {
return (
'multiValueHeaders' in event &&
(!event.headers || !('x-vercel-id' in event.headers))
)
}

export const extractHashingOptions = (text: string): ScryptOptions => {
const [_hash, ...options] = text.split('|')

Expand Down

0 comments on commit b6e6f1e

Please sign in to comment.