mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
9468e5cb4f
Extract functions from AuthenticationController to SessionManager GitOrigin-RevId: 86870ce03a762e1a837dcf493759e8851e759883
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
const _ = require('lodash')
|
|
|
|
const SessionManager = {
|
|
getSessionUser(session) {
|
|
const sessionUser = _.get(session, ['user'])
|
|
const sessionPassportUser = _.get(session, ['passport', 'user'])
|
|
return sessionUser || sessionPassportUser || null
|
|
},
|
|
|
|
setInSessionUser(session, props) {
|
|
const sessionUser = SessionManager.getSessionUser(session)
|
|
if (!sessionUser) {
|
|
return
|
|
}
|
|
for (const key in props) {
|
|
const value = props[key]
|
|
sessionUser[key] = value
|
|
}
|
|
return null
|
|
},
|
|
|
|
isUserLoggedIn(session) {
|
|
const userId = SessionManager.getLoggedInUserId(session)
|
|
return ![null, undefined, false].includes(userId)
|
|
},
|
|
|
|
getLoggedInUserId(session) {
|
|
const user = SessionManager.getSessionUser(session)
|
|
if (user) {
|
|
return user._id
|
|
} else {
|
|
return null
|
|
}
|
|
},
|
|
|
|
getLoggedInUserV1Id(session) {
|
|
const user = SessionManager.getSessionUser(session)
|
|
if (user != null && user.v1_id != null) {
|
|
return user.v1_id
|
|
} else {
|
|
return null
|
|
}
|
|
},
|
|
}
|
|
|
|
module.exports = SessionManager
|