@@ -678,6 +678,17 @@ export function superValidateSync<
678678
679679///////////////////////////////////////////////////////////////////////////////
680680
681+ /**
682+ * Cookie configuration options. The defaults are:
683+ * Path=/; Max-Age=120; SameSite=Strict;
684+ */
685+ export interface CookieSerializeOptions {
686+ path ?: string | undefined ;
687+ maxAge ?: number | undefined ;
688+ sameSite ?: 'Lax' | 'Strict' | 'None' ;
689+ secure ?: boolean | undefined ;
690+ }
691+
681692export function actionResult <
682693 T extends Record < string , unknown > | App . Error | string ,
683694 Type extends T extends string
@@ -691,8 +702,28 @@ export function actionResult<
691702 | {
692703 status ?: number ;
693704 message ?: Type extends 'redirect' ? App . PageData [ 'flash' ] : never ;
705+ cookieOptions ?: CookieSerializeOptions ;
694706 }
695707) {
708+ function cookieData ( ) {
709+ if ( typeof options === 'number' || ! options ?. message ) return '' ;
710+
711+ const extra = [
712+ `Path=${ options ?. cookieOptions ?. path || '/' } ` ,
713+ `Max-Age=${ options ?. cookieOptions ?. maxAge || 120 } ` ,
714+ `SameSite=${ options ?. cookieOptions ?. sameSite ?? 'Strict' } `
715+ ] ;
716+
717+ if ( options ?. cookieOptions ?. secure ) {
718+ extra . push ( `Secure` ) ;
719+ }
720+
721+ return (
722+ `flash=${ encodeURIComponent ( JSON . stringify ( options . message ) ) } ; ` +
723+ extra . join ( '; ' )
724+ ) ;
725+ }
726+
696727 const status =
697728 options && typeof options !== 'number' ? options . status : options ;
698729
@@ -704,9 +735,7 @@ export function actionResult<
704735 headers :
705736 typeof options === 'object' && options . message
706737 ? {
707- 'Set-Cookie' : `flash=${ encodeURIComponent (
708- JSON . stringify ( options . message )
709- ) } ; Path=/; Max-Age=120`
738+ 'Set-Cookie' : cookieData ( )
710739 }
711740 : undefined
712741 }
0 commit comments