Can anyone explain why is it trowing error?
I'm trying to fetch data from database with Credentials and check if in DB are any data corresponding to credentials but it says that **Cannot read property 'then' of undefined** 
I resolved promise and added .catch block but it keep saying same thing

```
UserSchema.statics.findByCredentials = function (email, password){
var User = this;

User.findOne({email}).then((user) => {
    if(!user) return Promise.reject();
    return new Promise((resolve, reject) => {
        bcrypt.compare(password, user.password, (err, res) => {
            if(res) {
                resolve(user);  
            }else{
                reject()
            }
        })
    })
})
};

app.post('/users/login', (req,res) => {
var body = _.pick(req.body, ['email', 'password']);

User.findByCredentials(body.email, body.password).then((user) => {
    res.send(user);
}).catch((e) =>{
    res.status(400).send();
})
});

```

here are my error details

```
TypeError: Cannot read property 'then' of undefined
at app.post (/home/vahe/node-projects/node-todo-api/server/server.js:96:51)
at Layer.handle [as handle_request] (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/layer.js:95:5)
at next (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/layer.js:95:5)
at /home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:335:12)
at next (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:275:10)
at /home/vahe/node-projects/node-todo-api/node_modules/body-parser/lib/read.js:130:5
at invokeCallback (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:224:16)
at done (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:213:7)
at IncomingMessage.onEnd (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:273:7)
at IncomingMessage.emit (events.js:182:13)
at endReadableNT (_stream_readable.js:1092:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:12690) 
UnhandledPromiseRejectionWarning: undefined
(node:12690) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12690) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
TypeError: Cannot read property 'then' of undefined
at app.post (/home/vahe/node-projects/node-todo-api/server/server.js:96:51)
at Layer.handle [as handle_request] (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/layer.js:95:5)
at next (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/layer.js:95:5)
at /home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:335:12)
at next (/home/vahe/node-projects/node-todo-api/node_modules/express/lib/router/index.js:275:10)
at /home/vahe/node-projects/node-todo-api/node_modules/body-parser/lib/read.js:130:5
at invokeCallback (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:224:16)
at done (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:213:7)
at IncomingMessage.onEnd (/home/vahe/node-projects/node-todo-api/node_modules/raw-body/index.js:273:7)
at IncomingMessage.emit (events.js:182:13)
at endReadableNT (_stream_readable.js:1092:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

```