In this episode, we're setting up the magic login link email feature for our application. That means when a user requests a login link, we want to send them an email with a special URL they can click to log in—super convenient!
First, we talk a bit about how you can test outgoing emails locally. You can use something like HELO on your computer, or if that's not an option, just set your mailer to log
so emails get written to your log files. Either way, you'll see what the email looks like before sending it for real.
We then create a new LoginController
to handle what happens when someone clicks the magic login link, and register the needed route. At this point, the controller doesn't do much; it just proves the route is hooked up.
Next up, we use Laravel's artisan command to make a new Mailable class called MagicLoginLink
, customize its subject and the email markdown template, and wire up the right route for the login in the email button. We update the email template to include a button that points at our auth session route, which we'll hook up properly in future steps.
Then, we add the logic to actually send the email when requested, making sure the user sees a successful message flashed on the login page (e.g., "Check your email for your magic login link"). This wraps up the basic magic login email feature—email gets sent, user gets notified, and everything's flowing!
By the end of this episode, your app can send a magic login email and do a basic redirect on submission. Next time, we'll get into actually linking the user to a real, secure login flow via the email link.