Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastifyCookieClearCookie sets maxAge to zero #304

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function fastifyCookieSetCookie (reply, name, value, options) {

function fastifyCookieClearCookie (reply, name, options) {
const opts = Object.assign({ path: '/' }, options, {
expires: new Date(1),
signed: undefined,
maxAge: undefined
expires: new Date(0),
maxAge: 0,
signed: undefined
})

return fastifyCookieSetCookie(reply, name, '', opts)
Expand Down
4 changes: 2 additions & 2 deletions test/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ test('share options for setCookie and clearCookie', (t) => {
t.equal(cookies.length, 1)
t.equal(cookies[0].name, 'foo')
t.equal(cookies[0].value, '')
t.equal(cookies[0].maxAge, undefined)
t.equal(cookies[0].maxAge, 0)

t.ok(new Date(cookies[0].expires) < new Date())
})
Expand Down Expand Up @@ -1054,7 +1054,7 @@ test('clearCookie should include parseOptions', (t) => {
t.equal(cookies.length, 1)
t.equal(cookies[0].name, 'foo')
t.equal(cookies[0].value, '')
t.equal(cookies[0].maxAge, undefined)
t.equal(cookies[0].maxAge, 0)
t.equal(cookies[0].path, '/test')
t.equal(cookies[0].domain, 'example.com')

Expand Down