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

with-passport-and-next-connect redefines response end function as async #51628

Open
1 task done
ntaranov opened this issue Jun 21, 2023 · 6 comments
Open
1 task done
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers

Comments

@ntaranov
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

---

Which example does this report relate to?

with-passport-and-next-connect

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Here in with-passport-and-next-connect end function is defined as async. This cannot be correct as it's called without await by the framework creating a race condition.

This is a result of

  • Trying to override sync end
  • Using async @hapi\iron apis

Expected Behavior

This can be fixed either by saving the session somewhere else or by using a sync cryptography API.

To Reproduce

Run the example, see API resolved without sending a response for /api/auth/session, this may result in stalled requests. in the console.

@ntaranov ntaranov added the examples Issue was opened via the examples template. label Jun 21, 2023
@mause-01

This comment was marked as off-topic.

@ntaranov
Copy link
Author

The issue you're encountering with the "with-passport-and-next-connect" package is that it redefines the response end function as async, which is causing conflicts. To fix this issue, you can try the following solution:

1.Open the file where the issue is occurring (e.g., the file where you're using the "with-passport-and-next-connect" package).

2.Look for the section of code that redefines the response end function. It might be something like res.end = async function() { ... }.

3. Modify the code to remove the async keyword from the function definition. For example, change it to res.end = function() { ... }.

Save the file and restart your Next.js server

I sorts of explained this option in my initial report, the problem is that the example relies on @hapi\iron methods that are async only, which I also explained.

@Aakashdeep-Srivastava
Copy link

Aakashdeep-Srivastava commented Oct 22, 2023

Lets do this.... Assign this to me.

@ghost
Copy link

ghost commented Dec 18, 2023

I am new to open source. Please let me know if this has been resolved or not. Also if possible give me a brief about the issue. So that i can resolve it. Any help would be appreciated.

@ghost
Copy link

ghost commented Dec 27, 2023

Can i get a brief about this issue?

@ghost
Copy link

ghost commented Dec 27, 2023

I am able to reproduce this when i am sending a GET request to api/login.

mohammedDhinojwala pushed a commit to mohammedDhinojwala/next.js that referenced this issue Aug 6, 2024
…ion and Handle session asynchronously before ending the response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers
Projects
None yet
4 participants