How to set Cookie and Location redirect in response object ? Only either is working

I have the folowing code, when i use statusCode 200 it adds cookie but redirect doesnot work. When i use 304 it redirects but cookie is not set. How can i do both ? Is it possible ?

	  const response = {
	statusCode: 200,
	    headers: {
		"Access-Control-Allow-Origin" : "*",
		"Access-Control-Allow-Credentials" : true,
		"Set-Cookie": 'data=dflsdjfhlsd',
		"Location":"http://127.0.0.1:8040/#/dashboard",
	    },
	    body: JSON.stringify({
	      message: data,
	    }),
	  };
	  callback(null, response);

First, you probably meant to use 301, 302, 303, 307 or 308 rather than 304.

Second, You need to add a P3P header. The value doesn’t seem to matter but some browsers won’t accept the cookie if you don’t.

1 Like