Skip to content

Commit 8bde0f5

Browse files
committed
refactor: fix cookie attributes handling for secure context and ensure Max-Age is set correctly
1 parent 6a70f85 commit 8bde0f5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib/cookies.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ export const cookieUtils = {
1818
`${name}=${encodeURIComponent(value)}`,
1919
`expires=${expires.toUTCString()}`,
2020
`path=/`,
21-
`SameSite=Strict`
21+
`SameSite=Strict`,
22+
`Max-Age=${days * 24 * 60 * 60}`
2223
]
2324

24-
if (location.protocol === 'https:') {
25-
attributes.push('Secure')
26-
}
25+
if (window.isSecureContext) {
26+
attributes.push('Secure')
27+
}
2728

2829
document.cookie = attributes.join('; ')
2930

0 commit comments

Comments
 (0)