Skip to content

Commit

Permalink
test cooke on subdomain
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgr committed Dec 18, 2024
1 parent 36f455b commit 0df503f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vtex/utils/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ export const setSegmentBag = (
const token = serialize(segment);
setSegmentInBag(ctx, { payload: segment, token });

const hostname = (new URL(req.url)).hostname;
const cookieDomain = hostname.startsWith(".") ? hostname : `.${hostname}`;

// Avoid setting cookie when segment from request matches the one generated
if (vtex_segment !== token) {
setCookie(ctx.response.headers, {
value: token,
name: SEGMENT_COOKIE_NAME,
domain: hostname === "localhost" ? "localhost" : cookieDomain,
path: "/",
secure: true,
httpOnly: true,
Expand Down

0 comments on commit 0df503f

Please sign in to comment.