diff --git a/errors/fixes-for-with-passport-and-next-connect.md b/errors/fixes-for-with-passport-and-next-connect.md new file mode 100644 index 0000000000000..ff2dd7d04bfc2 --- /dev/null +++ b/errors/fixes-for-with-passport-and-next-connect.md @@ -0,0 +1,21 @@ +--- +title: middleware keeps redefining response.end as async +--- + +## `` + +#### Why This Error Occurred + + + +asynchronous handling of res.end using async/await keyword + +#### Possible Ways to Fix It + + + +remove the async keyword from the function definition + +### Useful Links + + diff --git a/examples/with-passport-and-next-connect/lib/session.js b/examples/with-passport-and-next-connect/lib/session.js index eb2792d659f63..814b0ff7517bb 100644 --- a/examples/with-passport-and-next-connect/lib/session.js +++ b/examples/with-passport-and-next-connect/lib/session.js @@ -29,13 +29,13 @@ export default function session({ name, secret, cookie: cookieOpts }) { // We are proxying res.end to commit the session cookie const oldEnd = res.end - res.end = async function resEndProxy(...args) { + res.end = function resEndProxy(...args) { if (res.finished || res.writableEnded || res.headersSent) return if (cookieOpts.maxAge) { req.session.maxAge = cookieOpts.maxAge } - const token = await createLoginSession(req.session, secret) + const token = createLoginSession(req.session, secret) res.setHeader('Set-Cookie', serialize(name, token, cookieOpts)) oldEnd.apply(this, args)