Skip to content

Commit 52bbb3b

Browse files
nonoakijKikobeats
andauthored
fix(cookies): set options when deleting cookies (#890)
* fix(cookies): set options when deleting cookies * fix(cookies): array destructuring to assign 'options' as 'args[0]' * feat(cookies): add test for deleting cookie with Secure, HttpOnly, and SameSite=none * Create sharp-games-carry.md --------- Co-authored-by: Kiko Beats <[email protected]>
1 parent 7c658a6 commit 52bbb3b

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

.changeset/sharp-games-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@edge-runtime/cookies": patch
3+
---
4+
5+
fix(cookies): set options when deleting cookies

packages/cookies/src/response-cookies.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ export class ResponseCookies {
8787
| [key: string]
8888
| [options: Omit<ResponseCookie, 'value' | 'expires'>]
8989
): this {
90-
const [name, path, domain] =
91-
typeof args[0] === 'string'
92-
? [args[0]]
93-
: [args[0].name, args[0].path, args[0].domain]
94-
return this.set({ name, path, domain, value: '', expires: new Date(0) })
90+
const [name, options] =
91+
typeof args[0] === 'string' ? [args[0]] : [args[0].name, args[0]]
92+
return this.set({ ...options, name, value: '', expires: new Date(0) })
9593
}
9694

9795
[Symbol.for('edge-runtime.inspect.custom')]() {

packages/cookies/test/response-cookies.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ test('delete cookie with domain and path', async () => {
209209
])
210210
})
211211

212+
test('delete cookie with Secure, HttpOnly, and SameSite=none', () => {
213+
const headers = new Headers()
214+
const cookies = new ResponseCookies(headers)
215+
216+
cookies.delete({
217+
name: '__Secure-foo',
218+
secure: true,
219+
httpOnly: true,
220+
sameSite: 'none',
221+
})
222+
223+
expect(headers.getSetCookie()).toEqual([
224+
'__Secure-foo=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=none',
225+
])
226+
})
227+
212228
test('options are not modified', async () => {
213229
const options = { maxAge: 10000 }
214230
const headers = new Headers({ 'content-type': 'application/json' })

0 commit comments

Comments
 (0)