File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -763,7 +763,12 @@ class ExpressServer implements IExpressHttpServer {
763763 }
764764
765765 response . headers . forEach ( ( [ name , value ] ) => {
766- res . setHeader ( name , value ) ;
766+ // setHeader replaces previous value, so cookies set by hooks would be lost behind auth cookie
767+ if ( name . toLowerCase ( ) === 'set-cookie' ) {
768+ res . append ( name , value ) ;
769+ } else {
770+ res . setHeader ( name , value ) ;
771+ }
767772 } ) ;
768773 res . status ( response . status ) ;
769774 if ( response . message ) {
Original file line number Diff line number Diff line change @@ -75,6 +75,20 @@ describe('auth.beforeLogout', () => {
7575 expect ( res . headers [ 'set-cookie' ] [ 0 ] ) . toContain ( 'Expires=Thu, 01 Jan 1970 00:00:00 GMT' ) ;
7676 } ) ;
7777
78+ it ( 'can remove custom cookies together with auth cookie' , async ( ) => {
79+ hooks . push ( async ( { adminforth, extra } ) => {
80+ adminforth . auth . removeCustomCookie ( { response : extra . response , name : 'plugin_state' } ) ;
81+ } ) ;
82+
83+ const res = await logout ( await loginCookie ( ) ) ;
84+
85+ const brandSlug = admin . config . customization . brandNameSlug ;
86+ expect ( res . headers [ 'set-cookie' ] ) . toEqual ( [
87+ expect . stringContaining ( `adminforth_${ brandSlug } _plugin_state=;` ) ,
88+ expect . stringContaining ( `adminforth_${ brandSlug } _jwt=;` ) ,
89+ ] ) ;
90+ } ) ;
91+
7892 it ( 'clears auth cookie and runs remaining hooks when a hook throws' , async ( ) => {
7993 const called : string [ ] = [ ] ;
8094 hooks . push (
You can’t perform that action at this time.
0 commit comments