Last active
August 29, 2015 14:20
-
-
Save ptasker/9a5f736a3a3a24ed3719 to your computer and use it in GitHub Desktop.
NodeJS promises issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function authenticate() { | |
return getUsername() | |
.then(function (username) { | |
return getUser(username); | |
}) | |
// chained because we will not need the user name in the next event | |
.then(function (user) { | |
return getPassword() | |
// nested because we need both user and password next | |
.then(function (password) { | |
if (user.passwordHash !== hash(password)) { | |
throw new Error("Can't authenticate"); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment