next-persist
Advanced tools
Comparing version 1.0.9 to 1.1.0
{ | ||
"name": "next-persist", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "Bridging the gap between client-side persistence and server-side rendering", | ||
@@ -5,0 +5,0 @@ "main": "src/next-persist.js", |
@@ -41,9 +41,20 @@ /** | ||
arguments: | ||
req (object) - request object from the context object from Next.js data-fetching methods | ||
if application is running server-side: | ||
req (object) - request property from the context object from Next.js data-fetching methods | ||
if application is running client-side: | ||
req (boolean) - should be 'false' | ||
state (object) - object from application containing state | ||
cookieName (string) - the name of the cookie specified in setCooking config | ||
*/ | ||
// if application is running server-side, parse and return cookie from request object | ||
// if application is running client-side, parse and return cooking from document object | ||
nextPersistCookie.getCookie = (req) => cookie.parse(req ? req.ctx.req.headers.cookie || '' : document.cookie); | ||
nextPersistCookie.getCookie = (req, state, cookieName) => { | ||
// if application is running client-side, parse and return cookie from browser | ||
if (!req) { | ||
const stateFromCookie = Cookie.get(cookieName); | ||
return stateFromCookie ? JSON.parse(stateFromCookie) : state | ||
} // if application is running server-side, parse and return cooking from request body | ||
else return cookie.parse(req.ctx.req.headers.cookie || ''); | ||
} | ||
module.exports = nextPersistCookie; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10423
229