In this episode, we tackle user sign-in for our app. You'll see that a lot of what we do is almost identical to the registration process, which is great because it means we can re-use much of our code and workflow. We start by building out a new login modal and controller, setting up the appropriate routes, and making sure only guests can access the sign-in and register pages (so signed-in users don't see these!).
We set up the login modal by copying our existing register modal and customizing it for login—removing unnecessary fields like "name" and "confirm password," and making sure it's focused on just email and password. Once the form is in place, we hook it up to our navigation to display the modal when a user clicks "Sign In."
Then, we wire up the form to actually submit data to the backend. We check out the routes, make sure we hit Fortify's /login
endpoint, and confirm that sign-in works. Next, we add the "Remember Me" checkbox so users stay signed in if they want. We show how to bind this checkbox to the form submission and do a little code spelunking in Fortify to see how authentication and the remember
field are handled under the hood.
Finally, we confirm everything works (including setting the "remember me" cookie in the database when checked), and wrap up by pointing out that we're now fully set up to sign users in. As a next step, we'll look at how to let users sign out, which we'll cover in the following episode.