FST_ERR_REP_ALREADY_SENT

So this is not a question that was something that caused me pain for days. Incase anyone is using fastify and you are trying to use a middleware with the Prehandler Option and you are getting an error like this

{"type":"FastifyError","message":"Reply was already sent.","stack":"FastifyError: Reply was already sent.n    at _Reply.Reply.send (C:\Users\User\Desktop\eventsApp\EventsApp\node_modules\fastify\lib\reply.js:124:26)n    at successResponse (C:\Users\User\Desktop\eventsApp\EventsApp\src\response\success.js:2:24)n    at Object.createEvent (C:\Users\User\Desktop\eventsApp\EventsApp\src\repositories\eventRepository.js:59:16)n    at processTicksAndRejections (node:internal/process/task_queues:96:5)n    at async Object.newEvent (C:\Users\User\Desktop\eventsApp\EventsApp\src\services\eventService.js:23:21)n    at async Object.createEvent (C:\Users\User\Desktop\eventsApp\EventsApp\src\controllers\eventController.js:6:22)","name":"FastifyError","code":"FST_ERR_REP_ALREADY_SENT","statusCode":500},"msg":"Reply already sent"}

so what you should do is that in your middleware function get rid of the next() fastify automatically does this for you so doing it again sends your response or request twice. And also incase if mongoDB if you are trying to send a request to create a document including the next() creates the record twice