My Angular 11 (http://localhost:4200) is now talking to my node API server (http://localhost:3000). API server sends back a sessionID in a cookie, but subsequent browser request to API doesn't come with a cookie.
This is how node API sends back sessionID in a cookie
res.cookie('sessionID', 123);
F12 confirmed it's in Response Headers, Set-Cookie: sessionID=123; Path=/
Cookie is supposed auto-sent by browser along with every request. To read it in node: var mysessionid=req.cookie["sessionID"];
Tried the options mentioned in this post and github, still don't see sessionID
in F12's Request Headers:
const httpOptions =
{
headers: new HttpHeaders({'Content-Type': 'application/json', 'Access-Control-Request-Headers': 'content-type'}),
withCredentials: true,
};
this.http.post<any[]>('http://localhost:3000/anywhere', httpOptions, myData).subscribe(...);
And:
const httpOptions =
{
headers: new HttpHeaders({'Content-Type': 'application/json'}),
withCredentials: true,
'Access-Control-Allow-Headers': 'content-type'
};
I have an interceptor at Angular, to confirm if interceptor causing this no-cookie-sent, the above URL is excluded, meaning the header is not touched. Still cookie is not sent over to API server.
Am I doing it correctly since cookie is supposed automatically sent?