In this episode, we finally build the login page for our app! Previously, we had tested the login functionality, but we didn’t have the actual login form for users to interact with. So in this lesson, we hook everything up and get the frontend working.
First, we add a link to the login page inside our base layout, and then since we don’t want to start from scratch, we just copy the view from the register page and adjust it for login: remove the name field, update the form, and switch the headlining text. Now, the form only asks for email and password.
But, just copying the view isn’t enough—we also need to make sure our route actually returns the view. So we head to the login controller and hook up the correct view return. A quick browser refresh, and our new login page appears!
Of course, before moving on, it’s always a good idea to write a simple test to make sure this page loads correctly. We write a basic test using Pest that checks whether a GET request to /auth/login
returns successfully. All good!
Next, we check that our test database is empty and then go through the whole register and login flow in the browser. We even manually clear cookies to ensure we’re starting fresh.
Finally, since logout is missing, we take a moment to add logout functionality. To do this securely, we avoid a simple GET request (which is unsafe) and instead wrap the logout button in a POST form with CSRF protection. After a few small changes in the Blade template, logout works!
So by the end of this episode we've got the registration, login, and logout flows working nicely, and we’re ready to move on to something more interesting.