Skip to content

Expiring a cookie #708

@erkde

Description

@erkde

Hi there, am trying to figure how to clear/expire/delete a cookie - if this is possible? I have three pretty simple endpoints mocking a session, when you post in some credentials, it sets a cookie:

return res(
   ctx.cookie("auth-token", "random-string"),
   ctx.json({ authenticated: true })
)

when you get the session, it checks the cookie is there

return res(
  ctx.json({ authenticated: req.cookies["auth-token"] !== undefined })
)

and when you delete a session, it sets the expiry to the past:

const expires = new Date(moment().subtract(1, "second").toDate())
return res(
  ctx.cookie("auth-token", undefined, { expires })
  ctx.json({ authenticated: false })
)

the issue I'm seeing is, after deleting a session, even though the browser has cleared off the expired cookie, req.cookies("auth-token") still retains the old value on subsequent requests

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions