chore: simplify logoutController #1342

Merged
Sainan merged 2 commits from simplify-logout into main 2025-03-27 03:33:40 -07:00
Showing only changes of commit 57f6f37e85 - Show all commits

View File

@ -1,19 +1,24 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { Account } from "@/src/models/loginModel"; import { Account } from "@/src/models/loginModel";
const logoutController: RequestHandler = async (req, res) => { export const logoutController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); if (!req.query.accountId) {
const account = await Account.findById(accountId); throw new Error("Request is missing accountId parameter");
if (account) { }
account.Nonce = 0; const nonce: number = parseInt(req.query.nonce as string);
await account.save(); if (!nonce) {
throw new Error("Request is missing nonce parameter");
} }
res.writeHead(200, {
"Content-Type": "text/html",
"Content-Length": 1
});
res.end("1");
};
export { logoutController }; await Account.updateOne(
{
_id: req.query.accountId,
Nonce: nonce
},
{
Nonce: 0
}
);
res.end();
};