Hi there,
Thanks so much for sharing your code!
I'm currently on Day 7, and I ran into an error while using your code in authController.js for a POST API request.
The error message was:
{
"success": false,
"message": "Cannot read properties of undefined (reading 'findOne')"
}
I was able to fix the issue by making some changes:
try {
let user = await mongoose.connection
.collection("users")
.findOne({ username });
if (user) {
return res
.status(400)
.json({ success: false, message: "Username already in use" });
}
const securePassword = await bcrypt.hash(password, 10);
const userModel = mongoose.model("User");
user = new userModel({
username,
email,
password: securePassword,
accountType,
});
await user.save();
Could you please take a look and see if these changes are safe and follow best practices?
Really appreciate your work!
Hi there,
Thanks so much for sharing your code!
I'm currently on Day 7, and I ran into an error while using your code in
authController.jsfor a POST API request.The error message was:
I was able to fix the issue by making some changes:
Could you please take a look and see if these changes are safe and follow best practices?
Really appreciate your work!