Add missing path=/ to setCookieWithoutExpiration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 07:59:40 +08:00
parent 2a4aa9db00
commit ddab7b3fe9
2 changed files with 10 additions and 1 deletions

View File

@@ -50,7 +50,7 @@ export function setCookie(name, value, days=1) {
* @param {string} value - The cookie value. * @param {string} value - The cookie value.
*/ */
export function setCookieWithoutExpiration(name, value) { export function setCookieWithoutExpiration(name, value) {
document.cookie = name + "=" + (value || "") + "; Secure; SameSite=Lax"; document.cookie = name + "=" + (value || "") + "; path=/; Secure; SameSite=Lax";
} }
/** /**

View File

@@ -82,6 +82,15 @@ describe('cookieUtil', () => {
expect(str).toContain('Secure'); expect(str).toContain('Secure');
expect(str).toContain('SameSite=Lax'); expect(str).toContain('SameSite=Lax');
}); });
it('sets cookie with path=/', () => {
setCookieWithoutExpiration('pathKey', 'pathVal');
const written = cookieSetter.mock.calls.find(
(c) => c[0].startsWith('pathKey='),
);
expect(written[0]).toContain('path=/');
});
}); });
describe('deleteCookie', () => { describe('deleteCookie', () => {