redux-cookies-middleware
redux-cookies-middleware copied to clipboard
There is no ability to add additional params to cookies
How to add expires
or path
param when we set cookies?
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);
At this moment you cannot set a custom path for cookies. Do you wish to open a PR for it? Contributions welcome.
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.
Okey, but how do we specify if we want a secure cookie? Or when should it expire?
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 felt exactly the same. Especially that changing expiry shouldnt warrant providing as new setCookies implementation. Did you do anything regarding this?