Set multiple cookies in the returned response?

Hello,

I followed this example to set cookie in the lambda functions returned response and it works perfectly.

However, I have not figured out how to set multiple cookies.

I looked at this thread but did not quite get how to use multiValueHeaders. My code is the same as the first linked example.

Any help/pointer appreciated!

I haven’t tried this myself, but the way you set multiValueHeaders is like this:

return {
  statusCode: 200,
  multiValueHeaders: {
    "Set-Cookie": ["cookie1", "cookie2"]
  }
}

Does this work for you?

It works perfectly on local dev.

But unfortunately when deployed, it returned this error: error decoding lambda response: json: cannot unmarshal string into Go struct field .multiValueHeaders of type []interface {}

My package.json only has this 1 command:

"scripts": {
  "build": "netlify-lambda build src/functions"
},

and my netlify.toml only has build settings

[build]
  command = "npm run build"
  publish = "build"
  functions = "functions"

Not sure what i did wrong here. :thinking:

I don’t think you need Netlify Lamda. When you build a website with functions, Netlify automatically builds the functions without you having to specify anything else apart from the functions directory in netlify.toml.

In any case, if you can provide a repo to test, that would be great.

I use TS, need netlify-lambda to compile it. Sure, I’ll put up a repo tomorrow. Who knows I might discover I’d done something silly in the meantime! :laughing:

Thank you for your help so far!

Solved.

multiValueHeaders can only contain the Set-Cookie property. Anything else goes in headers as usual.

1 Like

Thank you for sharing, @ekafyi :netliconfetti: And @hrishikesh , thank you for these awesome debugging suggestions!

1 Like