grofers / redux-cookies-middleware

redux-cookies-middleware is a Redux middleware which syncs a subset of your Redux store state with cookies.
MIT License
81 stars 16 forks source link

There is no ability to add additional params to cookies #48

Open serhiiminin opened 6 years ago

serhiiminin commented 6 years ago

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

anubhav7495 commented 6 years ago

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 commented 6 years ago

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

buddyp450 commented 4 years ago

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.

LonguCodes commented 4 years ago

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

lucasjmatias commented 4 years ago

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?

AndersRemienHansen commented 4 years ago

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