

async function read (req, res, next) {
	if (req.user) {
		next();
	} else {
		next({status: 403, message: "Access denied"});
	}
}

async function write (req, res, next) {
	if (req.user && (req.user.role == "user" || req.user.role == "admin")) {
		next();
	} else {
		next({status: 403, message: "Access denied"});
	}
}

async function admin (req, res, next) {
	if (req.user && req.user.role == "admin") {
		next();
	} else {
		next({status: 403, message: "Access denied"});
	}
}

module.exports = {
	read,
	write,
	admin
};
