So when I try to register using this code
router.post(
"/register",
catchAsync(async (req, res, next) => {
const { username, password, email, number, address } = req.body.user;
const user = new User({
email,
username,
number,
address,
isVerified: false,
});
const registredUser = await User.register(user, username, password);
req.login(registredUser, (err) => {
if (err) {
return next(err);
}
console.log(registredUser);
req.flash("success", "Dobro došli na About Women!");
res.redirect("users/confirm");
});
})
);
it flashes error in the title. I tried doing everything even referencing to my old code but none of it worked. This is log I get from console:
node_modules\passport-local-mongoose\index.js:247
promise.then((result) => cb(null, result)).catch((err) => cb(err));
^
TypeError: cb is not a function
How can I fix it? Also I am using passport for user registration.
That error message points to line 247 of index.js in the passport-local-mongoose package. See https://github.com/saintedlama/passport-local-mongoose/blob/main/index.js#L247
That is in the register function:
schema.statics.register = function (user, password, cb) {
The arguments are expected to be user, password, and callback. You are passing user, username, and password, so at line 247 it is trying to use the password as a callback function, which fails with the error message you noted.