I am facing an issue with this code as it is returning the error "Model.findOne() no longer accepts a callback". I need to resolve this issue without downgrading my mongoose version.
`router.post('/login', async(req, res) => {
const email = req.body.email;
const password = req.body.password;
const userType = req.body.userType;
let userSchema;
let redirectUrl;
// Determine the user schema and redirect URL based on the user type
if (userType === 'customer') {
userSchema = Customers;
redirectUrl = '/customer/home';
} else if (userType === 'hotel_owner') {
userSchema = HotelOwners;
redirectUrl = '/hotel_owner/home';
} else if (userType === 'advertiser') {
userSchema = Advertisers;
redirectUrl = '/advertiser/home';
} else if (userType === 'destination_manager') {
userSchema = DestinationManagers;
redirectUrl = '/destination_manager/home';
} else if (userType === 'admin') {
userSchema = Admin;
redirectUrl = '/admin/home';
}
// Search for the user in the respective schema
await userSchema.find({ email: email, password: password })
.then(user => {
if (!user) {
// Return an error message if user is not found
res.status(401).send({
message: "Invalid email or password"
});
} else {
// Redirect the user to their home page
res.redirect(redirectUrl);
}
})
.catch(err => {
// Handle any errors
console.error(err);
res.status(500).send({
message: "An error occurred"
});
});
});`
Can someone help me in fixing this error to make the code work properly?