Skip to content

Commit

Permalink
feat: change cookie domain for faststore api's host
Browse files Browse the repository at this point in the history
  • Loading branch information
icazevedo committed Dec 7, 2023
1 parent 40ff694 commit 0975990
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/api/src/platforms/vtex/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import type { Context } from '../index'

const MATCH_DOMAIN_REGEXP = /(?:^|;\s*)(?:domain=)([^;]+)/i

export const setCookie = (headers: Headers, ctx: Context) => {
headers.getSetCookie().forEach((cookie) => ctx.storage.cookies.add(cookie))
const faststoreAPIHostname = new URL(`https://${ctx.headers.host}`).hostname

headers
.getSetCookie()
.forEach((cookie) =>
ctx.storage.cookies.add(
// Replaces original cookie domain for FastStore API's domain hostname
cookie.replace(MATCH_DOMAIN_REGEXP, `; domain=${faststoreAPIHostname}`)
)
)
}

export const getStoreCookie = (ctx: Context) => (headers: Headers) =>
Expand Down

0 comments on commit 0975990

Please sign in to comment.