catch block in invalidate sessions
This commit is contained in:
parent
bf0ca9784b
commit
50c6ad9630
|
@ -15,29 +15,33 @@ function makeSessionID(userId, sessionId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function invalidateSessions(userId, sessionIds = null) {
|
async function invalidateSessions(userId, sessionIds = null) {
|
||||||
let sessions = []
|
try {
|
||||||
|
let sessions = []
|
||||||
|
|
||||||
// If no sessionIds, get all the sessions for the user
|
// If no sessionIds, get all the sessions for the user
|
||||||
if (!sessionIds) {
|
if (!sessionIds) {
|
||||||
sessions = await getSessionsForUser(userId)
|
sessions = await getSessionsForUser(userId)
|
||||||
sessions.forEach(
|
sessions.forEach(
|
||||||
session =>
|
session =>
|
||||||
(session.key = makeSessionID(session.userId, session.sessionId))
|
(session.key = makeSessionID(session.userId, session.sessionId))
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// use the passed array of sessionIds
|
// use the passed array of sessionIds
|
||||||
sessions = Array.isArray(sessionIds) ? sessionIds : [sessionIds]
|
sessions = Array.isArray(sessionIds) ? sessionIds : [sessionIds]
|
||||||
sessions = sessions.map(sessionId => ({
|
sessions = sessions.map(sessionId => ({
|
||||||
key: makeSessionID(userId, sessionId),
|
key: makeSessionID(userId, sessionId),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await redis.getSessionClient()
|
const client = await redis.getSessionClient()
|
||||||
const promises = []
|
const promises = []
|
||||||
for (let session of sessions) {
|
for (let session of sessions) {
|
||||||
promises.push(client.delete(session.key))
|
promises.push(client.delete(session.key))
|
||||||
|
}
|
||||||
|
await Promise.all(promises)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error invalidating sessions: ${err}`)
|
||||||
}
|
}
|
||||||
await Promise.all(promises)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createASession = async (userId, session) => {
|
exports.createASession = async (userId, session) => {
|
||||||
|
|
Loading…
Reference in New Issue