Nikhil
Nikhil

Reputation: 1

Trouble Using 'js-cookie' Package with NPM: Cookie Handling Issue

I'm facing an issue with the js-cookie library in my Node.js application. I'm using it to manage cookies, specifically, I'm setting a cookie named 'gameData' with the value 'value', but when I try to retrieve the cookie value using Cookies.get('gameData'), it's returning undefined.

Here's a simplified version of my code:

const Cookies = require('js-cookie');

const generateCookies = () => {
  Cookies.set('gameData', 'value');
  console.log(Cookies.get('gameData'));
  console.log('Game started. Data stored in session cookie.');
}

const initializeItems = (req, res) => {
  generateCookies();
};

initializeItems();

I expect Cookies.get('gameData') to return the value 'value', which I've set using Cookies.set('gameData', 'value'), but it's logging undefined to the console instead.

console output:

undefined
Game started. Data stored in session cookie.

I have properly imported the js-cookie library at the beginning of my file, so I'm not sure why I'm getting undefined. Could there be something I'm missing or doing wrong in my code?

Any help would be greatly appreciated. Thank you in advance!

Upvotes: 0

Views: 184

Answers (1)

Mika
Mika

Reputation: 1

try to add secure :true
comme ca Cookies.set("authToken", token, { sameSite: "None", secure: true });

Upvotes: -1

Related Questions