I am redirecting a user to login page based on roles if they are not an admin to avoid access to a route, below is the code:
router.post('/gymcreate',async(req,res) => {
let userName = req.session.user.email;
let gymName = req.body.firstname;
let location = req.body.city;
let phoneNumber = req.body.mobile;
let priceRange = req.body.price;
try{
check(userName,gymName,location,phoneNumber,priceRange);
const creategym = await gymData.create(userName,gymName,location,phoneNumber,priceRange);
if(creategym){
res.status(200).redirect('/gyms')
}
else {
res.status(500).render('gymbars/creategym', {title: "Error", error: 'Internal Server Error'})
}
}
catch(e){
res.status(400).render('gymbars/creategym', {title: "Error", error: e})
}
});
Along with the redirect() I also want to send a message saying, "You do not have access to this page". Is there a way to do this without using client side javascript?