diff --git a/server/initializers/session.js b/server/initializers/session.js index 6fa03c0f..265e18ca 100644 --- a/server/initializers/session.js +++ b/server/initializers/session.js @@ -16,7 +16,24 @@ module.exports = upgradeInitializer('ah17', { if (error) { return callback(error) } else if (data) { - return callback(null, JSON.parse(data)) + let sessionData = null + try { + sessionData = JSON.parse(data) + } catch (e) { + return callback(e) + } + + if (!sessionData?.userId) { + return callback(null, false) + } + api.models.user.findByPk(sessionData.userId) + .then(function (user) { + if (!user) { + callback(null, false) + } + sessionData.user = user + callback(null, sessionData) + }).catch(callback) } else { return callback(null, false) } @@ -32,8 +49,7 @@ module.exports = upgradeInitializer('ah17', { const sessionData = { userId: user.id, csrfToken, - sesionCreatedAt: new Date().getTime(), - user + sesionCreatedAt: new Date().getTime() } user.update({ lastLoginAt: new Date() }).then(function () {