1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00
budibase/packages/worker/src/api/controllers/global/sessions.js

38 lines
861 B
JavaScript
Raw Normal View History

2021-07-08 10:30:14 +12:00
const {
getAllSessions,
getUserSessions,
invalidateSessions,
} = require("@budibase/backend-core/sessions")
2021-07-08 10:29:19 +12:00
exports.fetch = async ctx => {
ctx.body = await getAllSessions()
}
exports.find = async ctx => {
const { userId } = ctx.params
const sessions = await getUserSessions(userId)
ctx.body = sessions.map(session => session.value)
}
exports.invalidateUser = async ctx => {
const { userId } = ctx.params
await invalidateSessions(userId)
ctx.body = {
2021-07-08 10:30:14 +12:00
message: "User sessions invalidated",
2021-07-08 10:29:19 +12:00
}
}
exports.selfSessions = async ctx => {
const userId = ctx.user._id
ctx.body = await getUserSessions(userId)
}
exports.invalidateSession = async ctx => {
const userId = ctx.user._id
const { sessionId } = ctx.params
await invalidateSessions(userId, sessionId)
ctx.body = {
2021-07-08 10:30:14 +12:00
message: "Session invalidated successfully.",
2021-07-08 10:29:19 +12:00
}
}