Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-persist-cookie-storage

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-persist-cookie-storage - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

4

package.json
{
"name": "redux-persist-cookie-storage",
"version": "0.1.1",
"version": "0.2.0",
"description": "redux-persist storage adapter for cookies",
"main": "index.js",
"scripts": {
"test": "mocha test"
"test": "mocha test --timeout 15000"
},

@@ -9,0 +9,0 @@ "author": "Oliver Spindler <os@oliverspindler.com>",

@@ -20,5 +20,26 @@ # Redux Persist Cookie Storage Adapter

const store = createStore(reducer, undefined, autoRehydrate())
// By default, session cookies are used
persistStore(store, { storage: new CookieStorage() })
// Expiration time can be set via options
persistStore(store, { storage: new CookieStorage({
expiration: {
'default': 365 * 86400 // Cookies expire after one year
}
})
})
// Default expiration time can be overridden for specific parts of the store:
persistStore(store, { storage: new CookieStorage({
expiration: {
'default': null, // Session cookies used by default
'storeKey': 600 // State in key `storeKey` expires after 10 minutes
}
})
})
```
### Server

@@ -39,4 +60,7 @@

})
```
N.B.: Custom expiration times are not supported server-side at the moment.
## Development

@@ -43,0 +67,0 @@

@@ -9,2 +9,6 @@ var Cookies = require('cookies-js');

this.indexKey = options.indexKey || 'reduxPersistIndex';
this.expiration = options.expiration || {};
if (!this.expiration.default) {
this.expiration.default = null;
}

@@ -25,8 +29,25 @@ if (options.windowRef) {

CookieStorage.prototype.setItem = function (key, value, callback) {
this.cookies.set(this.keyPrefix + key, value);
var options = {};
var expires = this.expiration.default;
if (typeof this.expiration[key] !== 'undefined') {
expires = this.expiration[key]
}
if (expires) {
options["expires"] = expires;
}
this.cookies.set(this.keyPrefix + key, value, options);
// Update key index
var indexOptions = {};
if (this.expiration.default) {
indexOptions["expires"] = this.expiration.default;
}
this.getAllKeys(function (error, allKeys) {
if (allKeys.indexOf(key) === -1) {
allKeys.push(key);
this.cookies.set(this.indexKey, JSON.stringify(allKeys));
this.cookies.set(this.indexKey, JSON.stringify(allKeys), indexOptions);
}

@@ -33,0 +54,0 @@ callback(null);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc