Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code fixed that redefines the response.end as async at with-passport-and-next-connect #51628 #54400

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions errors/fixes-for-with-passport-and-next-connect.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the error message linked to?

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: middleware keeps redefining response.end as async
---

## ``

#### Why This Error Occurred

<!-- Explain why the error occurred. Ensure the description makes it clear why the warning/error exists -->

asynchronous handling of res.end using async/await keyword

#### Possible Ways to Fix It

<!-- Explain how to fix the warning/error, potentially by providing alternative approaches. Ensure this section is actionable by users -->

remove the async keyword from the function definition

### Useful Links

<!-- Add links to relevant documentation -->
4 changes: 2 additions & 2 deletions examples/with-passport-and-next-connect/lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


res.setHeader('Set-Cookie', serialize(name, token, cookieOpts))
oldEnd.apply(this, args)
Expand Down