improve: say the magic words to log the client out when nonce is invalidated (#250)
This commit is contained in:
		
							parent
							
								
									4f1e5ff326
								
							
						
					
					
						commit
						17244ea390
					
				@ -5,6 +5,14 @@ import { getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
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) {
 | 
			
		||||
        res.json({
 | 
			
		||||
            RegularCredits: 999999999,
 | 
			
		||||
@ -15,8 +23,6 @@ export const getCreditsController: RequestHandler = async (req, res) => {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    res.json({
 | 
			
		||||
        RegularCredits: inventory.RegularCredits,
 | 
			
		||||
 | 
			
		||||
@ -17,13 +17,7 @@ const inventoryController: RequestHandler = async (request: Request, response: R
 | 
			
		||||
    try {
 | 
			
		||||
        accountId = await getAccountIdForRequest(request);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        if ((e as Error).message == "Invalid accountId-nonce pair") {
 | 
			
		||||
            // 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 });
 | 
			
		||||
        response.status(400).send("Log-in expired");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user