Skip to content

Commit

Permalink
Futhur check for headersSent
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangvvo committed Jan 9, 2020
1 parent 9cb7b3c commit dd561a7
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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];

Expand All @@ -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 = () => {
Expand Down

0 comments on commit dd561a7

Please sign in to comment.