Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
redux-persist-cookie-storage
Advanced tools
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.
npm install --save redux-persist-cookie-storage
import { persistStore, persistCombineReducers } from 'redux-persist'
import { CookieStorage } from 'redux-persist-cookie-storage'
import Cookies from 'cookies-js'
// Cookies.defaults.domain = ...
const persistConfig = {
key: "root",
storage: new CookieStorage(Cookies/*, options */)
}
const rootReducer = persistCombineReducers(persistConfig, reducers)
const store = createStore(rootReducer, undefined)
const persistor = persistStore(store, {})
import { persistStore, persistCombineReducers } from 'redux-persist'
import { CookieStorage } from 'redux-persist-cookie-storage'
import Cookies from 'cookies-js'
const persistConfig = {
key: "root",
storage: new CookieStorage(Cookies/*, options */),
stateReconciler(inboundState, originalState) {
// Ignore state from cookies, only use preloadedState from window object
return originalState
}
}
const rootReducer = persistCombineReducers(persistConfig, reducers)
const store = createStore(rootReducer)
const persistor = persistStore(store, window.PRELOADED_STATE)
// Read-only mode: Use getStoredState method
import { persistStore, getStoredState } from 'redux-persist'
import { CookieStorage, NodeCookiesWrapper } from 'redux-persist-cookie-storage'
import Cookies from 'cookies'
const app = new Express()
app.use(Cookies.express())
app.use(async (req, res) => {
const cookieJar = new NodeCookiesWrapper(new Cookies(req, res))
const persistConfig = {
key: "root",
storage: new CookieStorage(cookieJar/*, options */),
stateReconciler(inboundState, originalState) {
// Ignore state from cookies, only use preloadedState from window object
return originalState
}
}
let preloadedState
try {
preloadedState = await getStoredState(persistConfig)
}
catch (e) {
// getStoredState implementation fails when index storage item is not set.
preloadedState = {}
}
const rootReducer = persistCombineReducers(persistConfig, reducers)
const store = createStore(rootReducer, preloadedState)
})
// Read-write mode: Create persistor
import { persistStore, getStoredState } from 'redux-persist'
import { CookieStorage, NodeCookiesWrapper } from 'redux-persist-cookie-storage'
import Cookies from 'cookies'
const configurePersistor = async (store) => {
return new Promise((resolve) => {
const persistor = persistStore(store, {}, () => {
resolve(persistor)
})
})
}
const app = new Express()
app.use(Cookies.express())
app.use(async (req, res) => {
const cookieJar = new NodeCookiesWrapper(new Cookies(req, res))
const persistConfig = {
key: "root",
storage: new CookieStorage(cookieJar/*, options */),
stateReconciler(inboundState, originalState) {
// Ignore state from cookies, only use preloadedState from window object
return originalState
}
}
const rootReducer = persistCombineReducers(persistConfig, reducers)
// Initialize store without preloaded state
const store = createStore(rootReducer)
// Wait until persistor has completed deserialization
const persistor = await configurePersistor(store)
// Force cookies to be set
await persistor.flush()
res.send(200, 'Done!')
})
// By default, session cookies are used
persistStore(store, { storage: new CookieStorage(Cookies) })
// Expiration time can be set via options
persistStore(store, { storage: new CookieStorage(Cookies, {
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(Cookies, {
expiration: {
'default': null, // Session cookies used by default
'storeKey': 600 // State in key `storeKey` expires after 10 minutes
}
})
})
// Other cookie options like domain, path and secure:
persistStore(store, { storage: new CookieStorage(Cookies, {
setCookieOptions: {
path: '/mypath'
}
})
})
npm test
FAQs
redux-persist storage adapter for cookies
The npm package redux-persist-cookie-storage receives a total of 2,741 weekly downloads. As such, redux-persist-cookie-storage popularity was classified as popular.
We found that redux-persist-cookie-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.