SoftwareBrothers / adminjs-fastify

MIT License
6 stars 13 forks source link

fix: auth route handlers not ending correctly #20

Closed mohd-akram closed 8 months ago

mohd-akram commented 8 months ago

The missing return in the protected routes handler caused the request to continue processing even after the redirect, leading to this error:

Error [ERR_HTTP_HEADERS_SENT]: Cannot write headers after they are sent to the client
    at ServerResponse.writeHead (node:_http_server:345:11)
    at safeWriteHead (/Users/user/code/project/node_modules/fastify/lib/reply.js:572:9)
    at onSendEnd (/Users/user/code/project/node_modules/fastify/lib/reply.js:621:5)
    at wrapOnSendEnd (/Users/user/code/project/node_modules/fastify/lib/reply.js:565:5)
    at next (/Users/user/code/project/node_modules/fastify/lib/hooks.js:289:7)
    at Object.fastifyCookieOnSendHandler (/Users/user/code/project/node_modules/@fastify/cookie/plugin.js:113:3)
    at next (/Users/user/code/project/node_modules/fastify/lib/hooks.js:295:30)
    at /Users/user/code/project/node_modules/@fastify/session/lib/fastifySession.js:201:9
    at Immediate._onImmediate (/Users/user/code/project/node_modules/@fastify/session/lib/session.js:180:11)
    at process.processImmediate (node:internal/timers:480:21) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Add returns to other async handlers too as is recommended.

mohd-akram commented 8 months ago

Is this good to merge? See the promise resolution section in the docs for more info on this.

github-actions[bot] commented 8 months ago

:tada: This PR is included in version 4.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: