Вылазит ошибка:
events.js:291
throw er; // Unhandled 'error' event
^
TypeError: user.comparePassword is not a function
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\config\passport.js:32:10
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\mongoose\lib\model.js:4884:16
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\mongoose\lib\model.js:4884:16
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\mongoose\lib\model.js:4907:21
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\mongoose\lib\query.js:4447:11
at C:\Users\Admin\OneDrive\Рабочий стол\node.js\Class atternder\Class attender\node_modules\kareem\index.js:136:16
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Emitted 'error' event on Function instance at:
вот стратегия аунтефикации которую я объявил
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
User.findOne({ email: email.toLowerCase() }, (err, user) => {
if (err) { return done(err); }
if (!user) {
return done(null, false, { msg: `Email ${email} not found.` });
}
if (!user.password) {
return done(null, false, { msg: 'Your account was registered using a sign-in provider. To enable password login, sign in using a provider, and then set a password under your user profile.' });
}
user.comparePassword(password, (err, isMatch) => {
if (err) { return done(err); }
if (isMatch) {
return done(null, user);
}
return done(null, false, { msg: 'Invalid email or password.' });
});
});
}));
вот сам метод comparePassword в model
userScema.methods.comparePassword = function comparePassword(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
cb(err, isMatch);
});
};
В чем проблема?