Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ function errorHandler(err) {
}

function auth({username, password}) {
const userQuery = hashStringAsync(password)
.then(hashPass => ({username, hashPass}))
const loginEvent = () => auditLogAsync({event: 'login', username})

return Promise
.resolve({username, password})
.catch(errorHandler)
.then(authValidate)
.tap(() => auditLogAsync({event: 'login', username}))
.tap(loginEvent)
.then(usersModel)
.then(users => {
// Inner Promise's value will bubble all the way up
// Note: This can also be further flattened... Keep reading.
return hashStringAsync(password)
.then(hashPass => users.findOneAsync({username, passHash}))
return userQuery
.then(users.findOneAsync)
.then(userFound)
})

Expand Down