const resp = require('../response.js')

module.exports = chkLogin = (req, res, next) => {
    try {
        if(req.session.hasOwnProperty("loggedIn") && req.session.loggedIn == true) {
            next();
        }
        else {
            req.session.loggedIn = false;
            return res.json(
                resp(
                    "Session Error",
                    "You are not Logged In. Please Login and try again",
                    null,
                    req
                )
            );
        }
    }
    catch(err) {
        return res.send(
            resp(
                "Server Error",
                "Error checking Login status",
                null,
                req
            )
        );
    }
}