redux-cookies-middleware icon indicating copy to clipboard operation
redux-cookies-middleware copied to clipboard

There is no ability to add additional params to cookies

Open serhiiminin opened this issue 6 years ago • 6 comments

How to add expires or path param when we set cookies?

serhiiminin avatar May 17 '18 09:05 serhiiminin

You can use a custom setCookie function to specify expiry for cookies.

import Raven from 'raven';

const paths = { ... };

const setCookie = (name, value, expiry, secure) => {
  // Add your custom implementation for setting cookie
};

const logger = msg => {
  // Log to Sentry
  Raven.captureException(msg);
};

const defaultEqualityCheck = lodash.isEqual;
const defaultDeleteCheck = val => val === null;

const customOptions = {
  logger,
  setCookie,
  defaultEqualityCheck,
  defaultDeleteCheck,
};

reduxCookiesMiddleware(paths, customOptions);

anubhav7495 avatar Aug 06 '18 09:08 anubhav7495

At this moment you cannot set a custom path for cookies. Do you wish to open a PR for it? Contributions welcome.

anubhav7495 avatar Aug 06 '18 09:08 anubhav7495

I honestly feel like the current ability to pass in your own setCookie implementation is fine. Ran across this issue and it took 2 minutes to implement. Given that the underlying cookie interface can be different from implementation to implementation (i.e. js-cookie expects days where-as some other api may expect ms) I feel like keeping this the way it is would be safer.

buddyp450 avatar Nov 25 '19 15:11 buddyp450

Okey, but how do we specify if we want a secure cookie? Or when should it expire?

LonguCodes avatar Feb 08 '20 13:02 LonguCodes

I wish I could set expiry in a simpler way, like this:

const paths = {
    'mydata': { name: 'cookie_name', expiry: 1 },
    'mydata2': { name: 'cookie_name_2', expiry: 15 },
}

I really don't want to implement my own setCookie since all I wanted is to change only the expire time and it'd be cool to be able to set different expiry times for different cookies.

May I implement this or this library is not suppose to work this way?

lucasjmatias avatar Apr 14 '20 09:04 lucasjmatias

@lucasjmatias felt exactly the same. Especially that changing expiry shouldnt warrant providing as new setCookies implementation. Did you do anything regarding this?

AndersRemienHansen avatar Jun 30 '20 15:06 AndersRemienHansen