Skip to content

Commit

Permalink
fastifyCookieClearCookie sets maxAge to zero (#304)
Browse files Browse the repository at this point in the history
* fastifyCookieClearCookie sets maxAge to zero

* apply suggestions

* update passed type

---------

Co-authored-by: Gürgün Dayıoğlu <hey@gurgun.day>
  • Loading branch information
aristofun and gurgunday authored Oct 9, 2024
1 parent f2aed09 commit 321932f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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: false
})

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

0 comments on commit 321932f

Please sign in to comment.