분명히 응답헤더에는 set-cookies가 잘찍히는데 브라우저 쿠키에 자동으로 저장이 안된다면?
원인은 sameSite였다. 명시하지않더라도 크롬정책에 의하여 기본값으로 세팅되어있다고한다.
해결방법은 서버에서 쿠키 구울때 sameSite:none랑 secure옵션을 추가해보자.
단 이렇게될경우 https에서만 작동된다. http 즉 로컬(http://localhost:3000/)로 개발할때는 크롬에서 막아 저장되지않으니 참고.
router.post(
"/",
async (res, req) => {
const jwt = 'test'
const cookieOptions = {
// sameSite: "strict",
sameSite: "none",
httpOnly: true,
secure: true,
// domain: "http://localhost",
// expires: new Date(Date.now() + parseInt(ENV.AUTH_EXPIREATION)),
maxAge: 24 * 60 * 60 * 1000,
path: "/",
};
res.cookie("x_auth", jwt, cookieOptions);
return res.status(200).json({
message: "jwt token issued",
jwt_token,
});
})
그래도 안되면 혹시 쿠키저장을 크롬에서 막고있지않은지 settings을 살펴본다.
localhost에서도 크롬에서 쿠키를 확인하고싶다면 cloudflare에서 터널링을 뚫어서하는 방법도있다고하는데 좀더 찾아봐야겠다.
참고
https://www.chromium.org/updates/same-site/
https://developers.google.com/search/blog/2020/01/get-ready-for-new-samesitenone-secure?hl=ko
반응형
'Network&etc > HTTP' 카테고리의 다른 글
[400에러] Unexpected token o in JSON at position 1 error (0) | 2022.09.15 |
---|---|
url 특수문자 처리 encodeURIComponent <-> decodeURIComponent (0) | 2022.08.04 |
Rest API 사용시 Caching 주의 (0) | 2022.07.14 |
cors 에러와의 만남 (0) | 2022.06.21 |
Failed to load resource: the server responded with a status of 404 (Not Found) (0) | 2022.06.21 |