1- function setCookie ( headers : Record < string , string > , name : string , value : string ) {
1+ function setCookie ( headers : Record < string , string > | undefined , name : string , value : string ) {
2+ if ( ! headers ) return
23 headers [ 'Set-Cookie' ] = `${ name } =${ value } ; Path=/; HttpOnly; SameSite=Strict`
34}
45
5- function getCookie ( headers : Record < string , string > , name : string ) {
6+ function getCookie ( headers : Record < string , string > | undefined , name : string ) {
7+ if ( ! headers ) return null
68 const cookie = headers [ name ]
79 if ( ! cookie ) return null
810 const cookies = cookie . split ( '; ' )
@@ -13,20 +15,21 @@ function getCookie(headers: Record<string, string>, name: string) {
1315 return null
1416}
1517
16- function deleteCookie ( headers : Record < string , string > , name : string ) {
18+ function deleteCookie ( headers : Record < string , string > | undefined , name : string ) {
19+ if ( ! headers ) return
1720 headers [ 'Set-Cookie' ] = `${ name } =; Path=/; HttpOnly; SameSite=Strict; Max-Age=0`
1821}
1922
2023const SESSION_COOKIE_NAME = 'SESSION_ID'
2124
22- export function getSessionCookie ( headers : Record < string , string > ) {
25+ export function getSessionCookie ( headers : Record < string , string > | undefined ) {
2326 return getCookie ( headers , SESSION_COOKIE_NAME )
2427}
2528
26- export function setSessionCookie ( headers : Record < string , string > , value : string ) {
29+ export function setSessionCookie ( headers : Record < string , string > | undefined , value : string ) {
2730 setCookie ( headers , SESSION_COOKIE_NAME , value )
2831}
2932
30- export function deleteSessionCookie ( headers : Record < string , string > ) {
33+ export function deleteSessionCookie ( headers ? : Record < string , string > ) {
3134 deleteCookie ( headers , SESSION_COOKIE_NAME )
3235}
0 commit comments