mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: added new hook static:sockets.validateSession (#7189)
* feat: added new hook * fix: improper .bind() call, +req in static:sockets.validateSession * fix: restored original sessionStore logic, +hook original logic to retrieve the sessionStore was not faulty, but was changed for the sake of changing things, which ultimately led to issues with tests, etc.
This commit is contained in:
@@ -10,6 +10,7 @@ var cookieParser = require('cookie-parser')(nconf.get('secret'));
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var logger = require('../logger');
|
||||
var plugins = require('../plugins');
|
||||
var ratelimit = require('../middleware/ratelimit');
|
||||
|
||||
|
||||
@@ -179,12 +180,17 @@ function validateSession(socket, callback) {
|
||||
if (!req.signedCookies || !req.signedCookies[nconf.get('sessionKey')]) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
db.sessionStore.get(req.signedCookies[nconf.get('sessionKey')], function (err, sessionData) {
|
||||
if (err || !sessionData) {
|
||||
return callback(err || new Error('[[error:invalid-session]]'));
|
||||
}
|
||||
|
||||
callback();
|
||||
plugins.fireHook('static:sockets.validateSession', {
|
||||
req: req,
|
||||
socket: socket,
|
||||
session: sessionData,
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user