This episode is for members only

Sign up to access "Build a Starter Kit With Inertia and Fortify" right now.

Get started
Already a member? Sign in to continue
Playing
35. Mail setup and forcing email verification

Episodes

0%
Your progress
  • Total: 5h 21m
  • Played: 0m
  • Remaining: 5h 21m
Join or sign in to track your progress

Transcript

00:00
OK, in this section, we are going to talk about email verification, which means when we create a new account,
00:05
we're going to send an email to that user to verify their account. They will be able to sign in by default and go ahead and access everything.
00:13
But we can protect particular routes and say, well, you have to be verified and you have to verify your email to be able to access a certain page.
00:22
So we're going to be setting everything up now, making sure that email gets sent. And then we're going to go ahead and protect a page like the dashboard to test this out.
00:30
OK, so let's go ahead and just update the user model first of all. This is where we need to start to enable this functionality. So to enable this, it's pretty straightforward.
00:40
We're just going to go ahead and implement the must verify email contract. That's all we need to do. And of course, we need to make sure
00:47
that over in our Fortify config, we have email verification enabled. OK, so once we've done this, now what's going to happen is when we create an account, it's
00:56
going to send off an email. Now, we don't have any email software set up at the moment. I'm going to go ahead and use MailPit. And I'll show you how to configure this.
01:04
This works for pretty much all operating systems. So you can go ahead and grab it. It's just a really nice, easy way to develop locally when you're sending email.
01:12
So I already have this installed. So what I'm going to do is go and set up a MailPit server. That will go ahead and run. And we can access that.
01:20
And we can see a kind of inbox here. So if we open this up in the browser, you can see we've got an email inbox here. So go ahead and install that or use any of the other software
01:31
that's available. OK, so to configure this, let's just quickly head over to our EMV file. We're going to go ahead and switch this over to 0.0.0.0
01:41
for our local machine. And to be honest, that's pretty much it. We can set our from email address and all that kind of stuff as well.
01:47
But we'll just leave that. OK, so now that we've done that, let's go ahead and create a new account. And we should see an email rolling.
01:53
So let's go ahead and say Mabel and Mabel at CodeCourse.com. And just enter a password. And sure enough, as we would expect, that user is now signed in and ready to go.
02:05
They can access anywhere in this application. But that will have sent them an email address. So you can see here, we've got an email asking us to verify this email.
02:14
So we're not going to touch that just yet. The first thing we're going to do is protect one of these pages. So let's, again, choose the dashboard
02:21
and protect this against verification. So if we head over to our web routes, find our dashboard. And we're going to head over to our kernel. And you'll see here that we've got this verified middleware.
02:31
So this is kind of a feature that's built into Laravel. But it's handled by Fortify to actually verify your email address. So that works really nicely.
02:41
So we're going to attach this verified middleware either in the route or in the controller to this dashboard. And as you can see already, we've got a change here. So let's go back to our home page
02:53
and click over to our dashboard. And we get the same message or error that we've seen previously, where we don't have a view or a route defined for this page.
03:04
And that is because we have disabled views. We want to create our own view for this. And we're actually going to create this out as a modal. Now, this modal is not going to allow us to type anything
03:15
into it. It's just going to say, you need to verify your email address to access this area. And then it's going to have a button within that modal
03:21
where, just when we click that, it's going to go ahead and resend off another email, just in case the user didn't get the email in the first place. So now that we have enabled this and attached this functionality
03:32
to the dashboard, we're getting the email through. We need to do a few things. We need to click through to actually verify our email address, which is going to work.
03:41
So if we go over to our dashboard now, that does work. It's all hooked up for us really nicely. The second thing we need to do, though, is go ahead and create this modal.
03:49
So if you need to toggle this, you can go ahead and do this in here. And let's find Email Verified At. We're going to get rid of that, head back over,
03:59
and we're back at the point where we see this message. So in the next episode, we're going to go ahead and create this modal out, which will remind the user to verify their email.
40 episodes5 hrs 21 mins

Overview

Let’s build our own Laravel starter kit with Inertia and include all the features you’d expect. We’ll implement authentication, email verification, profile photo uploads, two factor authentication, and more.

Fortify is a frontend agnostic authentication package for Laravel, meaning most of the work is done for us — we just need to build the frontend and make requests to the endpoints that Fortify registers.

Once you’re done, you’ll have a clean slate for building your next project, with the ability to control everything in your own starter kit.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.