Learning promises is an interesting process. Like many tools, there are common pitfalls to get stuck on. What makes promises somewhat unique is that it tends to be obvious that you're doing it wrong. Why? Promises are designed to solve a clear and well-understood problem: nested callbacks. As you start to use them however, you're code isn't that different. Obviously there's something you don't grok, but what?
The example that I'm going to walk through is a login. This involves:
1. Opening our connection
2. Getting the user's row from the DB based on email
3. Comparing the passwords
4. Updating the DB with a `token`
5. Releasing our connection
6. Returning the user data and token
Your new post is loading...