Skip to content

Commit

Permalink
chore(session): read user from db when loading session (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxvd authored May 13, 2024
1 parent 2f2d0ae commit 27b3a8e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions server/initializers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 () {
Expand Down

0 comments on commit 27b3a8e

Please sign in to comment.