fix: session not persisting to database in some scenarios

In some edge cases (e.g. SSO plugin redirecting the user immediately), with modern browsers, the request is never "completed" for speed. This causes a condition where the session object never persists to the database, even though it has changed. This added line forces a db persist on a successful login.

Context: https://github.com/expressjs/session/pull/484
This commit is contained in:
Julian Lam
2021-02-22 11:18:30 -05:00
parent 504fd107c7
commit 020f0b8322

View File

@@ -352,6 +352,7 @@ authenticationController.onSuccessfulLogin = async function (req, uid) {
version: req.useragent.version, version: req.useragent.version,
}); });
await Promise.all([ await Promise.all([
new Promise(resolve => req.session.save(resolve)),
user.auth.addSession(uid, req.sessionID), user.auth.addSession(uid, req.sessionID),
user.updateLastOnlineTime(uid), user.updateLastOnlineTime(uid),
user.updateOnlineUsers(uid), user.updateOnlineUsers(uid),