Cant set multiple cookies via nextjs custom headers in next config

Viewed 22

I'm setting the cookie via custom headers in the next.config.js file. Only the refresh token gets set. The second token is ignored.

            key: 'Set-Cookie',
            value: `RefreshTokenKey = "some_token"; AccessTokenKey = "some_token"; SameSite=Strict; HttpOnly`,
          }```
1 Answers

According to this documetation (read more here)

The Set-Cookie HTTP response header is used to send a cookie from the server to the user agent, so that the user agent can send it back to the server later. To send multiple cookies, multiple Set-Cookie headers should be sent in the same response.

You should send multiple headers, like this:

{
    headers: [
        {
            key: 'Set-Cookie',
            value: 'RefreshTokenKey = "some_token";',
        },
        {
            key: 'Set-Cookie',
            value: 'AccessTokenKey = "some_token";',
        },
    ]
}
Related