Authenticating users
In the last chapter, we saw how we handle user passwords in the Accounts
context, using the comeonin
library to sign and verify them. In this chapter, our focus is on extending our web interface to allow users to sign up and log in to our application, and also to restrict certain pages to logged in users. There's a myriad of libraries in the Elixir ecosystem that would allow us to achieve this in only a few lines of code. However, implementing our own authentication solution is beneficial for two reasons: it will give us the opportunity to explore Phoenix in greater depth and it will give us more freedom in how the authentication is made, allowing us to adapt it to fit our needs.
In order to have users authenticated, we first need to have the ability to create users in our application. We'll do this part from the bottom up, building the logic around the authentication of a user, and when that part is done, we'll work on allowing a user to sign up and log in.
As we hinted...