Search code examples
expressnext.jscookieshttpsrequest

losing cookie while requesting from subdomain to other subdomain


Currently I'm struggling with odd phenomenon about losing cookie..

Previously, I used AWS as my infra to handle frontend and backend as well.

previous scenario

Due to deployment issue, (frontend deployment sequence took too long) decided to use Vercel for frontend.

current scenario

Whats happening now, is that request started not to append cookie on request header.

Since I'm currently developing streaming service,

I have 3 actors for streaming scenario

I'll abbreviate as (a.domain.com , b.domain.com, c.domain.com)

a.domain.com = frontend b.domain.com = backend c.domain.com = dvd server

below is my scenario

streaming scenario

Looking at inspection table of cookie (chrome inspection tool->application tab), it seems that set-cookie works well.

set cookie works well

but while making request to "c.domain.com" I'm finding that cookie is lost on request header.

enter image description here

What I've tried??

  1. set credential : 'include' while fetching :: frontend

  2. allow CORS :: backend

  3. add Domain attribute while setting cookie :: backend (ex. Set-Cookie: wwwCookie=wwwCookie; Domain=.domain.com) <- not sure is it Domain=domain.com)

P.S

While comparing with previous request and current request(which fail)

I've found that partition key is added for current request. Does this relates to current issue?


Solution

  • Solved it!

    The problem was coming from AWS API Gateway configuration.

    I've needed to set CORS configuration of API Gateway service exactly same as my server configuration setting.

    Followed following article

    https://medium.com/@sharadokey/understanding-cors-and-cross-origin-cookies-bf36d624da78

    Sending Thanks to Sharadokey