import { NextFunction, Response, Request } from "express";
import { ApiResponse, ApiError } from "./rest-api-answer";

export default function (req : Request, res: Response, next: NextFunction) {
    if (!req.isAuthenticated) {
        const error : ApiResponse<ApiError> = new ApiResponse({
            code: "AUTH_REQUIRES",
            message: "Authentication is required"
        });
        return res.status(401).json(error);
    }
    next();
}