You only need to change the .authenticate method. Since connecting to the database is (or should be) an asynchronous operation, you need to add a promise object (see everyauth documentation ).
Assuming you have an ORM with user data matching the user object with username and password attributes (in my example, I will use the mongoose engine), this is how it looks:
.authenticate( function (login, password) { var promise = this.Promise(); db.find({ username:login }, function(err, user) { if (err) return promise.fulfill([err]); if ((!user) || (user.password != password)) return promise.fulfill(['Incorrect username or password!']); promise.fulfill(user); }); return promise; })
I have not tested it, but according to the documentation, it should work. Remember that errors must be stored in an array.
By the way: if you use only the password method, then you do not need to use a gun against a fly. :) Writing your own (not necessarily perfect, but working) authentication mechanism is very simple, and if you do not know how to do this, you should study it. This will be beneficial in the future, since authentication and security in general are very important in every web application.
source share