본문 바로가기

Error log

[express] res.clearCookie로 쿠키를 삭제할 수 없을 때

반응형

해당 사항은 직접 겪은 에러 상황은 아니지만 추후에 활용할 수 있을 것 같아서 기록합니다. 

 

res.clearCookie()를 express 공식문서에서 찾아보면 아래와 같은 내용을 확인할 수 있습니다. 

 

Web browsers and other compliant clients will only clear the cookie if the given options is identical to those given to res.cookie(), excluding expires and maxAge.

웹 브라우저 및 클라이언트는 지정된 옵션이 expires, maxAge를 제외하고 res.cookie()에서 제공된 옵션과 동일한 경우에만 쿠키를 지운다.

 

# 용례는 아래와 같습니다. 
res.cookie('name', 'tobi', { path: '/admin' })
res.clearCookie('name', { path: '/admin' })

 

clearCookie()를 활용하지 못해서

res.cookie('name', {})와 같이 쿠키를 없애거나,

client에서 해결을 보려는 시도가 생길 수 있습니다. 

 

express에서 쿠키를 삭제할 때 참고하면 좋을 것 같습니다.  

 

반응형