hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.64k stars 65 forks source link

nextjs 12.1.6 warn: You should not access 'res' after getServerSideProps resolves. #193

Closed PlopTheReal closed 2 years ago

PlopTheReal commented 2 years ago

I'm using next-connect 0.12.2 with passport in getServerSideProps like the following:

auth.js:

const auth = nc()
  .use(
    session({
      name: 'test',
      cookie: {
        maxAge: 60 * 60 * 8,
        httpOnly: true,
        secure: process.env.NODE_ENV === 'production',
        path: '/',
        sameSite: 'strict' 
      },
    })
  )
  .use(passport.initialize())
  .use(passport.session())

export default auth

index.js:

...
export async function getServerSideProps(ctx) {
 await auth.run(ctx.req, ctx.res) // triggers a warn
  ...
}

calling auth.run triggers a "warn - You should not access 'res' after getServerSideProps resolves."

hoangvvo commented 2 years ago

This is not related to next-connect but rather the express-session implementation. It tries to call a function when res.end is called, resulting in the above error.

I don't think we can do anything about it.