mirror of https://github.com/Budibase/budibase.git
8 changed files with 80 additions and 19 deletions
@ -0,0 +1,33 @@ |
|||
const { getAllSessions, getUserSessions, invalidateSessions } = require("@budibase/auth/sessions") |
|||
|
|||
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 = { |
|||
message: "User sessions invalidated" |
|||
} |
|||
} |
|||
|
|||
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 = { |
|||
message: "Session invalidated successfully." |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../../controllers/admin/sessions") |
|||
const adminOnly = require("../../../middleware/adminOnly") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.get("/api/admin/sessions", adminOnly, controller.fetch) |
|||
.get("/api/admin/sessions/self", controller.selfSessions) |
|||
.get("/api/admin/sessions/:userId", adminOnly, controller.find) |
|||
.delete("/api/admin/sessions/:userId", adminOnly, controller.invalidateUser) |
|||
.delete("/api/admin/sessions/self/:sessionId", controller.invalidateSession) |
|||
|
|||
module.exports = router |
|||
Loading…
Reference in new issue