Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
login: Promise.method(function (email, password) {
if (!email || !password) throw new Error("Email and password are both required.");
var storage = { user: null };
var fetchPromise = new this({ email: email.toLowerCase().trim() })
.bind(storage)
.fetch({ require: true })
.then(function (user) {
this.user = user;
return bcrypt.compareAsync(password, user.get('password'))
})
.then(function (samePassword) {
if (!samePassword) throw new Error("Invalid email or password");
return Promise.resolve(this.user);
})
return fetchPromise;
}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.