Skip to content

Commit

Permalink
Add secure cookie flag [closes #34]
Browse files Browse the repository at this point in the history
  • Loading branch information
nimishsinghal committed Aug 30, 2017
1 parent 024b633 commit 80e2a2d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ Description of each property:
* `logger(msg)`: This function can be used to capture errors occured inside `redux-cookies-middleware`. A good use-case for this could be to capture these errors and log them to Sentry or Errorception.
* This function has the following parameters:
* `msg`: Message you want to log with the help of this function.
* `setCookie(name, value, [, expiry])`: A function that creates the cookie. Provide a custom cookie setting implementation. Use-cases of this are implementation of cookie versioning or using the common cookie setting logic in your application. You will have to use a custom implementation of [`getCookie`]() as well.
* `setCookie(name, value, [, expiry, secure])`: A function that creates the cookie. Provide a custom cookie setting implementation. Use-cases of this are implementation of cookie versioning or using the common cookie setting logic in your application. You will have to use a custom implementation of [`getCookie`]() as well.
* This function has the following parameters:
* `name`: Name of the cookie.
* `value`: Value of the cookie.
* `expiry`: Expiry time (in days) of the cookie.
* `expiry`: Expiry time (in days) of the cookie. Default: 365 days (optional).
* `secure`: Either true or false, indicating if the cookie transmission requires a secure protocol (https). Default: false (optional).
* `defaultEqualityCheck(oldVal, newVal)`: A function to verify if the value before an action is dispatched and after the action is dispatched is equal or not. If the values are equal, the part of the store is not synced with the cookie. This is just to avoid setting cookies again and again if the value of that part of the store has not changed. You can set a custom equality check for every part of the store you want to sync with the cookies. Default value for this property is a function which does shallow comparison of two values using the `===` operator.
* This function has the following parameters:
* `oldVal`: Value of the part of the store before the reducers for a particular action execute.
Expand Down
3 changes: 2 additions & 1 deletion lib/cookieApi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cookieApi.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/cookieApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import jsCookie from 'js-cookie';

const getCookie = name => jsCookie.get(name);

const setCookie = (name, value, expiry = 365) => {
jsCookie.set(name, value, { expires: expiry, path: '/' });
const setCookie = (name, value, expiry = 365, secure = false) => {
jsCookie.set(name, value, { expires: expiry, path: '/', secure});
};

export { getCookie };
Expand Down

0 comments on commit 80e2a2d

Please sign in to comment.