I’m trying to login and authenticate users using my custom database, but I keep getting “Request to Webtask got ESOCKETTIMEDOUT”.
function login(email, password, callback) {
const MongoClient = require('mongodb').MongoClient;
const bcrypt = require('bcrypt');
const uri = `mongodb+srv://${configuration.DB_USERNAME}:${configuration.DB_PASSWORD}/${configuration.DB_HOST}/${configuration.DB_NAME}?retryWrites=true`;
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db('virtualcontrol').collection('profile_auths');
collection.findOne({ email: email }, function (err, user) {
if (err) return callback(err);
if (!user) return callback(new WrongUsernameOrPasswordError(email));
bcrypt.compare(password, user.password, function (err, isValid) {
if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));
return callback(null, {
user_id: user._id.toString(),
nickname: user.nickname,
email: user.email
});
});
});
client.close();
})
}
Here is my codes