sahat / hackathon-starter

A boilerplate for Node.js web applications
MIT License
34.8k stars 8.16k forks source link

Delete Account causes a server crash #1235

Closed YasharF closed 1 year ago

YasharF commented 1 year ago

node:events:491 throw er; // Unhandled 'error' event ^

Error: req#logout requires a callback function at req.logout.req.logOut (/mnt/c/temp/a/hackathon-starter/node_modules/passport/lib/http/request.js:65:44) at /mnt/c/temp/a/hackathon-starter/controllers/user.js:236:9 at /mnt/c/temp/a/hackathon-starter/node_modules/mongoose/lib/model.js:5353:18 at process.processTicksAndRejections (node:internal/process/task_queues:77:11) Emitted 'error' event on Function instance at: at /mnt/c/temp/a/hackathon-starter/node_modules/mongoose/lib/model.js:5355:15 at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Node.js v18.16.1

YasharF commented 1 year ago

It is because of changes in passport 0.6 - https://medium.com/passportjs/fixing-session-fixation-b2b68619c51d

The other major change is that that req.logout() is now an asynchronous function, whereas previously it was synchronous. For instance, a logout route that was previously:

app.post('/logout', function(req, res, next) {
  req.logout();
  res.redirect('/');
});

should be modified to:

app.post('/logout', function(req, res, next) {
  req.logout(function(err) {
    if (err) { return next(err); }
    res.redirect('/');
  });
});

As with logging in, logging out also clears session information. The keepSessionInfooption can be passsed to req.logout() to override this.

YasharF commented 1 year ago

Fixed with: https://github.com/sahat/hackathon-starter/commit/7bac14339a6fbf7bb4b460ae84ccc8f08314cf28