API: fire SB_SESSION_REMOVE upon logging out a session

This commit is contained in:
Rory& committed 2026-03-13 03:50:39 +01:00
1 parent 3fdc6a54aa
commit f9f1d8776b
2 files changed
+14 -2

No files matched your search

+8 -1
View File
@@ -18,7 +18,7 @@
import { route } from "@spacebar/api";
import { Request, Response, Router } from "express";
import { Session } from "@spacebar/util";
import { emitEvent, Session } from "@spacebar/util";
const router: Router = Router({ mergeParams: true });
export default router;
@@ -42,5 +42,12 @@ router.post(
if (req.session) await Session.remove(req.session);
res.status(204).send();
if (req.session)
await emitEvent({
session_id: req.session.session_id,
event: "SB_SESSION_REMOVE",
origin: "Self logout",
});
},
);
+6 -1
View File
@@ -17,7 +17,7 @@
*/
import { route } from "@spacebar/api";
import { createHash } from "node:crypto";
import { Session, Snowflake } from "@spacebar/util";
import { emitEvent, Session, Snowflake } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { SessionsLogoutSchema } from "../../../schemas/api/users/SessionsSchemas";
import { In } from "typeorm";
@@ -69,6 +69,11 @@ router.post(
for (const session of sessions) {
await session.remove();
await emitEvent({
session_id: session.session_id,
event: "SB_SESSION_REMOVE",
origin: "Sessions logout",
});
}
res.status(204).send();
},