From 5f77c7df320fa28e0d24869f06ab05efc20dc81f Mon Sep 17 00:00:00 2001 From: Alex Draper Date: Tue, 8 Nov 2022 16:46:42 -0800 Subject: [PATCH 1/5] Allow setting domain when deleting cookies --- packages/astro/src/core/cookies/cookies.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index f999db8a16b6..2d0af7acd1c6 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -11,9 +11,7 @@ interface AstroCookieSetOptions { secure?: boolean; } -interface AstroCookieDeleteOptions { - path?: string; -} +interface AstroCookieDeleteOptions extends Pick {} interface AstroCookieInterface { value: string | undefined; @@ -75,6 +73,9 @@ class AstroCookies implements AstroCookiesInterface { expires: DELETED_EXPIRATION, }; + if (options?.domain) { + serializeOptions.domain = options.domain; + } if (options?.path) { serializeOptions.path = options.path; } From 4981e47344e8ba48e0f357ec0befe49b956ac6a3 Mon Sep 17 00:00:00 2001 From: Alexander Draper Date: Wed, 9 Nov 2022 10:05:39 -0800 Subject: [PATCH 2/5] Add delete cookie with domain tests --- packages/astro/test/units/cookies/delete.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/astro/test/units/cookies/delete.test.js b/packages/astro/test/units/cookies/delete.test.js index 571a3e40d736..67fa1306bc23 100644 --- a/packages/astro/test/units/cookies/delete.test.js +++ b/packages/astro/test/units/cookies/delete.test.js @@ -56,5 +56,16 @@ describe('astro/src/core/cookies', () => { expect(headers).to.have.a.lengthOf(1); expect(headers[0]).to.match(/Path=\/subpath\//); }); + + it('can provide a domain', () => { + let req = new Request('http://example.com/'); + let cookies = new AstroCookies(req); + cookies.delete('foo', { + domain: '.example.com', + }); + let headers = Array.from(cookies.headers()); + expect(headers).to.have.a.lengthOf(1); + expect(headers[0]).to.match(/Domain=\.example\.com/); + }); }); }); From f35d644d170778656fd5f148810a70db1def825c Mon Sep 17 00:00:00 2001 From: Alexander Draper Date: Wed, 9 Nov 2022 12:08:19 -0800 Subject: [PATCH 3/5] Fix syntax for AstroCookieDeleteOptions type --- packages/astro/src/core/cookies/cookies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index 2d0af7acd1c6..73996f51fb42 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -11,7 +11,7 @@ interface AstroCookieSetOptions { secure?: boolean; } -interface AstroCookieDeleteOptions extends Pick {} +type AstroCookieDeleteOptions = Pick; interface AstroCookieInterface { value: string | undefined; From 5f5ca5abd50e3f1fbc8f6d50e9d2c1247da001e5 Mon Sep 17 00:00:00 2001 From: Alexander Draper Date: Wed, 9 Nov 2022 12:09:59 -0800 Subject: [PATCH 4/5] Add changeset --- .changeset/small-ravens-cover.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/small-ravens-cover.md diff --git a/.changeset/small-ravens-cover.md b/.changeset/small-ravens-cover.md new file mode 100644 index 000000000000..ef188180afa5 --- /dev/null +++ b/.changeset/small-ravens-cover.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Allow setting domain when deleting cookies From 01e6d1dc63367b0a8876474f880eb5ea88c3f4b6 Mon Sep 17 00:00:00 2001 From: Alexander Draper Date: Thu, 10 Nov 2022 09:26:05 -0800 Subject: [PATCH 5/5] Update to a minor change rather than a patch --- .changeset/small-ravens-cover.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/small-ravens-cover.md b/.changeset/small-ravens-cover.md index ef188180afa5..67b8e31f03e1 100644 --- a/.changeset/small-ravens-cover.md +++ b/.changeset/small-ravens-cover.md @@ -1,5 +1,5 @@ --- -'astro': patch +'astro': minor --- Allow setting domain when deleting cookies