Skip to content

Commit

Permalink
Use getSetCookie to allow multiple set-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
lariciamota committed Dec 4, 2023
1 parent 38577e6 commit 5e1aa79
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/platforms/vtex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Context {
locale: string
flags: FeatureFlags
searchArgs?: Omit<SearchArgs, 'type'>
cookies?: string | null
cookies?: string[] | null
}
headers: Record<string, string>
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/platforms/vtex/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Context } from '../index'

export const setCookie = (headers: Headers, ctx: Context) => {
ctx.storage.cookies = headers?.get('set-cookie') ?? ''
}
ctx.storage.cookies = headers?.getSetCookie() ?? []
}
4 changes: 3 additions & 1 deletion packages/core/src/pages/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const handler: NextApiHandler = async (request, response) => {
: 'no-cache, no-store'

if (extensions.cookies && !hasErrors) {
response.setHeader('set-cookie', extensions.cookies)
extensions.cookies.forEach((cookie) =>
response.setHeader('set-cookie', cookie)
)
}

response.setHeader('cache-control', cacheControl)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const execute = async <V extends Maybe<{ [key: string]: unknown }>, D>(
): Promise<{
data: D
errors: unknown[]
extensions: { cacheControl?: CacheControl; cookies: string | null }
extensions: { cacheControl?: CacheControl; cookies: string[] | null }
}> => {
const { operationName, variables, query: maybeQuery } = options
const query = maybeQuery ?? persistedQueries.get(operationName)
Expand Down

0 comments on commit 5e1aa79

Please sign in to comment.