I am creating a website and to do so, the Admin Account has access to create posts. While doing this, I have come across the error of when running the postLaunchCourse function sends me to 403 (No access) page and wont post it.
The code:
exports.getLaunchCourse = (req, res) => {
res.render("admin/launch-course", {
isAdmin: req.user && req.user.role === "admin" ? true : false,
isAutherized: req.user ? true : false,
username: req.user ? req.user.username : null,
});
};
// Type : POST
// Access : Private (Only For Admin)
// @Desc : Upload Course To Server
exports.postLaunchCourse = (req, res, next) => {
const title = req.body.title;
const description = req.body.description;
const price = req.body.price;
const thumbnail = req.file ? req.file.path : null;
const facultyAccess = req.body.facultyAccess.split(",");
const tags = req.body.tags.split(",");
cloudinary.v2.uploader.upload(thumbnail, (error, result) => {
deleteFileHandler.deleteFileHandler(thumbnail);
const course = new Course({
creator: req.user,
title: title,
description: description,
price: price,
thumbnail: result.url,
tags: tags,
facultyAccess: facultyAccess,
});
course
.save()
.then((course) => {
console.log("Course Created Successfully");
res.redirect("/course/" + course._id);
})
.catch((err) => {
const error = new Error("Wasn't able to Create-Course");
next(error);
});
});
};
I’ve tried changing the code and looking at other fixes but it wont work. I am expecting the post function to run properly and for it to post onto Remote Courses section.