@@ -75,7 +75,7 @@ export const getSignedCookie: GetSignedCookie = async (
7575 return obj as any
7676}
7777
78- export const setCookie = ( c : Context , name : string , value : string , opt ?: CookieOptions ) : void => {
78+ export const generateCookie = ( name : string , value : string , opt ?: CookieOptions ) : string => {
7979 // Cookie names prefixed with __Secure- can be used only if they are set with the secure attribute.
8080 // Cookie names prefixed with __Host- can be used only if they are set with the secure attribute, must have a path of / (meaning any path at the host)
8181 // and must not have a Domain attribute.
@@ -93,16 +93,20 @@ export const setCookie = (c: Context, name: string, value: string, opt?: CookieO
9393 } else {
9494 cookie = serialize ( name , value , { path : '/' , ...opt } )
9595 }
96+ return cookie
97+ }
98+
99+ export const setCookie = ( c : Context , name : string , value : string , opt ?: CookieOptions ) : void => {
100+ const cookie = generateCookie ( name , value , opt )
96101 c . header ( 'Set-Cookie' , cookie , { append : true } )
97102}
98103
99- export const setSignedCookie = async (
100- c : Context ,
104+ export const generateSignedCookie = async (
101105 name : string ,
102106 value : string ,
103107 secret : string | BufferSource ,
104108 opt ?: CookieOptions
105- ) : Promise < void > => {
109+ ) : Promise < string > => {
106110 let cookie
107111 if ( opt ?. prefix === 'secure' ) {
108112 cookie = await serializeSigned ( '__Secure-' + name , value , secret , {
@@ -120,6 +124,17 @@ export const setSignedCookie = async (
120124 } else {
121125 cookie = await serializeSigned ( name , value , secret , { path : '/' , ...opt } )
122126 }
127+ return cookie
128+ }
129+
130+ export const setSignedCookie = async (
131+ c : Context ,
132+ name : string ,
133+ value : string ,
134+ secret : string | BufferSource ,
135+ opt ?: CookieOptions
136+ ) : Promise < void > => {
137+ const cookie = await generateSignedCookie ( name , value , secret , opt )
123138 c . header ( 'set-cookie' , cookie , { append : true } )
124139}
125140
0 commit comments