forked from OpenWF/SpaceNinjaServer
		
	For bootstrapper v0.11.11, out now. Reviewed-on: OpenWF/SpaceNinjaServer#2735 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			33 lines
		
	
	
		
			893 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			893 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import type { RequestHandler } from "express";
 | 
						|
import { Account } from "../../models/loginModel.ts";
 | 
						|
import { handleNonceInvalidation } from "../../services/wsService.ts";
 | 
						|
 | 
						|
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) {
 | 
						|
        handleNonceInvalidation(req.query.accountId as string);
 | 
						|
    }
 | 
						|
 | 
						|
    res.writeHead(200, {
 | 
						|
        "Content-Type": "text/html",
 | 
						|
        "Content-Length": 1
 | 
						|
    });
 | 
						|
    res.end("1");
 | 
						|
};
 |