improve: say the magic words to log the client out when nonce is invalidated (#250)

This commit is contained in:
Sainan 2024-05-31 13:17:10 +02:00 committed by GitHub
parent 4f1e5ff326
commit 17244ea390
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -5,6 +5,14 @@ import { getInventory } from "@/src/services/inventoryService";
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
export const getCreditsController: RequestHandler = async (req, res) => { export const getCreditsController: RequestHandler = async (req, res) => {
let accountId;
try {
accountId = await getAccountIdForRequest(req);
} catch (e) {
res.status(400).send("Log-in expired");
return;
}
if (config.infiniteResources) { if (config.infiniteResources) {
res.json({ res.json({
RegularCredits: 999999999, RegularCredits: 999999999,
@ -15,8 +23,6 @@ export const getCreditsController: RequestHandler = async (req, res) => {
return; return;
} }
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
res.json({ res.json({
RegularCredits: inventory.RegularCredits, RegularCredits: inventory.RegularCredits,

View File

@ -17,13 +17,7 @@ const inventoryController: RequestHandler = async (request: Request, response: R
try { try {
accountId = await getAccountIdForRequest(request); accountId = await getAccountIdForRequest(request);
} catch (e) { } catch (e) {
if ((e as Error).message == "Invalid accountId-nonce pair") { response.status(400).send("Log-in expired");
// TODO: Figure out some way to tell the game to stop trying with this nonce.
// For now, we'll have to be a little nasty.
response.destroy();
return;
}
response.status(400).json({ error: (e as Error).message });
return; return;
} }