SpaceNinjaServer/src/controllers/api/logoutController.ts
Sainan a75e6d6b95
All checks were successful
Build / build (push) Successful in 51s
Build Docker image / docker-amd64 (push) Successful in 52s
Build Docker image / docker-arm64 (push) Successful in 47s
chore: add warning coverage for cyclic includes (#2407)
and some initial refactoring to avoid it where possible

Reviewed-on: #2407
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-07-04 16:49:25 -07:00

34 lines
945 B
TypeScript

import { RequestHandler } from "express";
import { Account } from "@/src/models/loginModel";
import { sendWsBroadcastTo } from "@/src/services/wsService";
export const logoutController: RequestHandler = async (req, res) => {
if (!req.query.accountId) {
throw new Error("Request is missing accountId parameter");
}
const nonce: number = parseInt(req.query.nonce as string);
if (!nonce) {
throw new Error("Request is missing nonce parameter");
}
const stat = await Account.updateOne(
{
_id: req.query.accountId,
Nonce: nonce
},
{
Nonce: 0
}
);
if (stat.modifiedCount) {
// Tell WebUI its nonce has been invalidated
sendWsBroadcastTo(req.query.accountId as string, { logged_out: true });
}
res.writeHead(200, {
"Content-Type": "text/html",
"Content-Length": 1
});
res.end("1");
};