Allow setting domain when deleting cookies (#5341)
* Allow setting domain when deleting cookies * Add delete cookie with domain tests * Fix syntax for AstroCookieDeleteOptions type * Add changeset * Update to a minor change rather than a patch Co-authored-by: Matthew Phillips <matthew@skypack.dev>
This commit is contained in:
parent
dced4a8a26
commit
6b156dd3b4
3 changed files with 20 additions and 3 deletions
5
.changeset/small-ravens-cover.md
Normal file
5
.changeset/small-ravens-cover.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': minor
|
||||
---
|
||||
|
||||
Allow setting domain when deleting cookies
|
|
@ -11,9 +11,7 @@ interface AstroCookieSetOptions {
|
|||
secure?: boolean;
|
||||
}
|
||||
|
||||
interface AstroCookieDeleteOptions {
|
||||
path?: string;
|
||||
}
|
||||
type AstroCookieDeleteOptions = Pick<AstroCookieSetOptions, 'domain' | 'path'>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue