I am trying to migrate my express application to tsoa and I was using express-session originally for authentication purpose. I am doing some testing on the compatibility but I found that it seems like there are some issue when I try to regenerate a header.
My two route inside the controller:
@Get("/refreshauth")
public async test_refresh_auth(
@Request() req: any
): Promise<any> {
await req.session.regenerate(function (err: any) {});
console.log(req.sessionID)
return Promise.resolve({message: 'success'});
}
@Get("/authtest")
public async test_auth(
@Request() req: any
): Promise<any> {
req.session.test = (req.session.test) ? req.session.test + 1 : 1;
console.log(req.sessionID)
console.log(req.session.test);
return Promise.resolve({message: 'success'});
}
The test_refresh_auth function works fine if I test that only. However, when I try the test_refresh_auth function after doing a few times test_auth, an error occurs.
[ERROR] :: Error: Unable to find the session to touch
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
[0] at new NodeError (node:internal/errors:400:5)
[0] at ServerResponse.setHeader (node:_http_outgoing:663:11)
I know that this error occurred because the header was set and probably started on the body but I am not sure which part of the code is causing this issue. I assume it is because of some weird interaction of express session and tsoa. It would be nice if someone could kindly inform the problem here and provide a solution.