In this episode, we're diving into authentication using Laravel Fortify! Now that our backend is set up and CORS errors are gone, it's time to get login working and start pulling through user details from our API.
We kick off by installing Laravel Fortify, which pretty much gives us all the authentication stuff out of the box—login, registration, profile updates, and more. If you want, you can roll your own, but Fortify makes things super easy so we can focus on building the rest of the app.
After updating our backend to use the correct Fortify routes, we clean up our frontend login form structure to make things a little tidier and get ready for validation messages. Then we take a peek at all the auto-registered routes that Fortify sets up for us.
We hit the login route from our frontend and, expectedly, get an error because there's no user yet. So we switch over to Tinker and create a user in the database. With a new user set up, we clear any old cookies from the browser (super important for these sessions!) and try logging in again. This time, it works! We're redirected as expected, and hitting our /user
API endpoint returns all the user details correctly.
We wrap up by tweaking the Nuxt config so users are redirected to the dashboard upon login. All set up—authentication is now up and running in our app! In the next episode, we’ll probably look into customizing this further and making the auth flow even smoother.