Thursday, 1 June 2017

TypeError: done is not a function

TypeError: done is not a function I'm using passport.js for the authentication and session. I am using email to Authenticate from passsport but when the done is called on verification, I get done is not a function.

at Promise.<anonymous> (/Users/sultan/Desktop/too2/controllers/users.js:39:28)
at Promise.<anonymous> (/Users/sultan/Desktop/too2/node_modules/mongoose/lib/promise.js:120:8) 

Code

  // LOCAL LOGIN =============================================================
passport.use('local-login', new LocalStrategy({
    usernameField : 'email',
    passwordField : 'password'
    //passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
},
function( email, password, done) {
    if (email)
        email = email.toString().toLowerCase();

    // asynchronous
    process.nextTick(function() {
        User.findOne({ email:  email }, function(err, user) {
            // if there are any errors, return the error
            if (err)
                return done(err);

            // if no user is found, return the message
            if (!user)
        //(/Users/sultan/Desktop/too2/controllers/users.js:39:28)
                return done(null, false, {message: 'No user found.'});

            if (!user.validPassword(password))
                return done(null, false, {message: 'Oops! Wrong Password'});

            // all is well, return user
            else
                return done(null, user);
        });
    });

}));

Error

I'm getting this err :"done is not a function".
plz respond if you know what the problem is.



via Sultan Zaid

No comments:

Post a Comment