diff --git a/src/utils/cookieUtil.js b/src/utils/cookieUtil.js index 246ff2c..c172857 100644 --- a/src/utils/cookieUtil.js +++ b/src/utils/cookieUtil.js @@ -50,7 +50,7 @@ export function setCookie(name, value, days=1) { * @param {string} value - The cookie value. */ export function setCookieWithoutExpiration(name, value) { - document.cookie = name + "=" + (value || "") + "; Secure; SameSite=Lax"; + document.cookie = name + "=" + (value || "") + "; path=/; Secure; SameSite=Lax"; } /** diff --git a/tests/unit/utils/cookieUtil.test.js b/tests/unit/utils/cookieUtil.test.js index 57a47c9..5d98250 100644 --- a/tests/unit/utils/cookieUtil.test.js +++ b/tests/unit/utils/cookieUtil.test.js @@ -82,6 +82,15 @@ describe('cookieUtil', () => { expect(str).toContain('Secure'); 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', () => {