diff --git a/.changesets/11718.md b/.changesets/11718.md new file mode 100644 index 000000000000..09c40430f2b0 --- /dev/null +++ b/.changesets/11718.md @@ -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 diff --git a/packages/auth-providers/dbAuth/api/src/shared.ts b/packages/auth-providers/dbAuth/api/src/shared.ts index 342ad8ba9310..ba7417150767 100644 --- a/packages/auth-providers/dbAuth/api/src/shared.ts +++ b/packages/auth-providers/dbAuth/api/src/shared.ts @@ -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 } } @@ -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('|')