From dd561a71c12ab6248b02873dd50cb114046be430 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Thu, 9 Jan 2020 01:12:57 -0500 Subject: [PATCH] Futhur check for headersSent --- src/index.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 16722fcf..1ba4b4f1 100644 --- a/src/index.js +++ b/src/index.js @@ -60,13 +60,9 @@ const session = (options = {}) => { }); return (req, res, next) => { - /** - * Modify req and res to "inject" the middleware - */ if (req.session) return next(); // check for store readiness before proceeded - if (!storeReady) return next(); // TODO: add pathname mismatch check @@ -77,7 +73,6 @@ const session = (options = {}) => { req.cookies = req.cookies || (req.headers && typeof req.headers.cookie === 'string' && parseCookie(req.headers.cookie)) || {}; - // Get sessionId cookie from Next.js parsed req.cookies req.sessionId = req.cookies[name]; @@ -103,9 +98,7 @@ const session = (options = {}) => { // Proxy res.end res.end = function resEndProxy(...args) { // If res.end() is called multiple times, do nothing after the first time - if (ended) { - return false; - } + if (res.headersSent || res.finished || ended) return false; ended = true; // save session to store if there are changes (and there is a session) const saveSession = () => {