In this episode, we roll up our sleeves and dive into setting up email verification for users in our app. Basically, when someone creates a new account, we'll send them a verification email to confirm their email address. By default, they can still sign in and use the app, but we learn how to protect specific routes (like the dashboard) so that only users with verified emails can access them.
We start by updating the user model and making sure email verification is enabled in the Fortify config. To actually send emails during development, we set up MailPit—a handy tool to catch and view emails sent from your local machine. The episode covers configuring your .env
file to connect to MailPit and quickly demonstrates creating a test account to see the verification email in action.
From there, we apply Laravel's built-in verified
middleware to the dashboard route, blocking unverified users. Since we've disabled the default views, we get an error at first. This sets us up for the next step: building a custom modal to notify users they need to verify their email, plus a button so they can easily request another verification email if needed.
So, by the end of this episode, you've set up the core logic for email verification and restricted access appropriately. Next up, we'll make that modal to improve the user experience even further!