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

redux-persist storage adapter for cookies

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-9.2%
Maintainers
1
Weekly downloads
 
Created
Source

Travis branch

Redux Persist storage adapter for cookies. Works in the browser and in Node.js with cookie-parser output. This makes it suitable for universal / isomorphic applications.

Installation

npm install --save redux-persist-cookie-storage

Usage

Browser

import { persistStore, autoRehydrate } from 'redux-persist'
import CookieStorage from 'redux-persist-cookie-storage'

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

// Read-only mode: Use plain object output of cookie parser
import { persistStore, autoRehydrate } from 'redux-persist'
import CookieStorage from 'redux-persist-cookie-storage'
import cookieParser from 'cookie-parser'

const app = new Express()

app.use(cookieParser())

app.use((req, res) => {
  const store = createStore(reducer, undefined, autoRehydrate())
  const cookies = req.cookies
  persistStore(store, { storage: new CookieStorage({ cookies }) })
})

// Read-write mode: Use actual cookie jar implementation
import { persistStore, autoRehydrate } from 'redux-persist'
import CookieStorage from 'redux-persist-cookie-storage'
import Cookies from 'cookies'

const app = new Express()

app.use(Cookies.express())

app.use((req, res) => {
  const store = createStore(reducer, undefined, autoRehydrate())
  const cookies = new Cookies(req, res)
  persistStore(store, { storage: new CookieStorage({ cookies }) })
})

N.B.: Custom expiration times are not supported server-side at the moment.

Development

Running tests

npm test

FAQs

Package last updated on 15 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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