cookiesjs-cookie

js-cookie not setting cookies when secure flag is enabled


I have this simple function that sets a cookie

Cookies.set('accesstoken', res.data.accesstoken);

I wanted to make it secure but whenever I put

Cookies.set('accesstoken', res.data.accesstoken, { secure: true });

The cookie is not set


Solution

  • As per the js-cookie documentation:

    secure

    Either true or false, indicating if the cookie transmission requires a secure protocol (https).

    Default: No secure protocol requirement.

    You need to use https in order to set the cookie using {secure:ture}