cookies keep resetting with eel python

36 Views Asked by At

my app made using python's eel library expects to retrieve data from cookies, the data is not critical and only contains a string of the last path the user worked with, so storing that in a database isn't ideal. However, cookies keeps resetting whenever the app starts.

I tried retrieving and storing the cookies like you normally would with js I use cookie.js from https://github.com/florian/cookie.js/


// store
function rememberLastPath(path){
    cookie.set('lastPath', path);
}

// retrieve
function getLastPath(){
   cookie.get('lastPath');
}

this works but when the app is restarted cookies are reset.

1

There are 1 best solutions below

0
Carlos Pinto On

Ok, the snippet does not provide too much context other than you are trying to set and get a cookie called lastPath to store the last workspace path.

Some of the most common root causes for cookie persistence errors are:

  • Is an expiration date being set when calling cookie.set()? - An explicit expiration may be needed.

function rememberLastPath(path) {
  cookie.set('lastPath', path, 
  {
    expires: 30 // expires in 30 days
  });
}

  • Does cookie.set() return any errors, warnings or response that could provide clues?. If so, please share them.

function setCookie(key, value) {
  try {
    cookie.set(key, value);
  } catch (error) {
    console.error('Error setting cookie', error);
    throw error;
  }
}

  • What browser are you using?. Some browsers like chrome require cookies to be set via HTTP only.
  • Is the domain being passed to cookie.set() correctly?.

const domain = '.example.com';
cookie.set(key, value, {
  domain
});

  • Can you see the cookie in the browser dev tools?. If so, please share the information you can see there.