This episode is for members only

Sign up to access "Passwordless Authentication with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
08. Sending the magic login link again

Transcript

00:00
Once we've registered the user within this action by calling handle from asController, down here we want to send that email so they can actually sign in. Of course, we don't need to
00:10
because they can head over to the login page to request one. But when we're registering, we expect to have a more convenient way to sign in. Now, how do we do this? Well, what we can actually do is inject in the SendMagicLink action that we previously created for our login process inside of here. So, we can pull that in and then we can just invoke it from in here by calling the
00:32
handle method. Now, we know that handle gives us back the user that we've just created. So, what we can do is assign this user. Now, we have an instance of that user that's been created and we can go ahead and invoke or handle the SendMagicLink action. Now, that requires, if we remember, an email address to be passed in. We have that user now, so we can just pass in
00:57
the email address in there and that should trigger that action to send an email. And remember, this SendMagicLink is not triggering the controller part of this. It's triggering just the handle method of this, which is just responsible for one thing and that is sending the email. Okay, let's try this out. So, I'm going to go ahead and register mabel at codecourse.com
01:19
again and let's go ahead and enter the name. Hit register and we should have a magic login link sent to Mabel. Hit login and there we go. We are signed in. Easy as that. We'd already created the action that is responsible for sending the email or anything else we need to do. So, we've just reused that within the registration process really conveniently to perform that same action.

Episode summary

In this episode, we're making the user registration process smoother by automatically sending out a magic login link right after someone registers. Instead of just letting the user go to the login page and request a login link themselves, we're hooking in the same SendMagicLink action we use during the login process and running it straight after creating the user.

We walk through how to inject and use the SendMagicLink action, showing how simple it is to reuse our existing code. After registering the new user, we trigger the handle method on our send link action, passing in the freshly registered user's email address. This instantly sends out the login email—no extra steps required.

To prove it all works, we go ahead and register a test user, watch the link get sent out automatically, and confirm that the sign-in happens as expected. It's a quick and convenient update that makes our registration flow a lot more user-friendly!

Episode discussion

No comments, yet. Be the first!