const User = require("../models/User");

async function isAdmin(req, res, next) {
    try {
        const user = await User.findOne(req.user).lean();
        if (user && user.admin) {
            return next();
        }
        res.json({ status: "error", msg: "unauthorized" });
    } catch (err) {
        res.json({ status: "error", msg: err.message });
    }
}

module.exports = {
    isAdmin
}