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
05. Installing Fortify

Episodes

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

Transcript

00:00
So if you've not used Laravel Fortify before, we're going to take this episode to really importantly get it installed, have a look around, figure out what we need to do so we
00:08
can start to visualize getting this implemented into our Inertia front end. Now, Laravel Fortify is a front end agnostic implementation of all the authentication features
00:20
that you'd need for an application. Basically, it just provides you all the controllers and functionality you need to register users, log them in, sign them out, set up two-factor authentication,
00:31
all the stuff that we're going to be implementing in this course. So we're going to implement every single Fortify feature. So let's just install this, have a look at our root list,
00:41
see what we've been given, and then we'll take a look around the config to see how that's going to help us as well. So let's go over to the installation section
00:48
and, of course, pull Laravel Fortify in with Composer. We'll go ahead and publish the config file, which is incredibly important, so we can start to configure this, and then we'll
00:59
go ahead and run our database migrations. Now, at the moment, let's take a look at our users table. You can see what columns we've got here, the standard stuff that we get with Laravel.
01:08
Once we go ahead and migrate here, you'll notice that these will slightly change. So we've got the two-factor stuff in here now, which is really important.
01:17
This is going to store our two-factor secret, our recovery codes, and if this was confirmed. So we don't really need to worry too much about the database schema because Fortify will handle
01:26
all of this for us, but it's good to see that that's changed. OK, the first thing that we're going to do is jump over to Fortify Config to have a look here.
01:33
So let's open this up and come down and do this line by line. So the guard, we don't really need to change unless we're building an API, which we're not doing. Passwords, you can configure for the models and stuff
01:45
that you're working with on the database table you're working with. We don't really need to worry about that. Email and username can be changed over as well.
01:53
So you can have a username or an email being configured. But what we're really interested in, if we just come down here, is go all the way down here to our views. So we do not need to register views.
02:08
The reason being is that we are working within a client-side kind of single-page application, although we're using Inertia. We are going to build up all of our own views.
02:18
Now, I said that this was sort of framework agnostic or front-end agnostic. Views are provided in some respects to get this working, but we don't need to register these.
02:28
So we're actually going to set this to false. In fact, I'm going to keep that to true for now, because we're going to look at our root list and how this changes.
02:33
But we are going to be setting that to false in just a second. So we'll talk about that in a moment. Now, the next thing is the feature list. So you can see here that this provides a list of features
02:43
that you can enable and disable. And that's also really important, because we need to control this on our back-end and our front-end as well when we
02:52
start to implement each of these features. So we are going to take an episode to talk about how we can hide things on the client side based on the features that are actually enabled or disabled.
03:02
So for example, if I disabled the registration feature, we wouldn't want to see a create an account link, and we wouldn't want to allow a user to submit a form to create an account.
03:14
You probably wouldn't toggle these too often, but we want to make sure this is implemented properly. So you can go ahead and toggle and change these. I'm going to enable all of these.
03:23
So I'm just going to uncomment out the email verification here. And that's pretty much it. So let's take a look at our root list,
03:30
because this is going to give us a good idea as to how this is working. So we're going to say phpArtisan and root list. And let's have a look.
03:38
So if you'd have run this before you installed Fortify, you'd just have your home controller root and a couple of other things. But you can see that this has provided
03:45
a huge amount of routes. So we've got login, register, reset password, the two-factor stuff, password confirmation. We've got the update profile information stuff,
03:56
more two-factor stuff here as well. So let's go and just have a look at the root count. We've got 32. We're going to go ahead and set views to false,
04:05
since we're working with inertia here. And we're going to disable these. And now let's go ahead and run this root list again. You can see that's down to 25.
04:13
So we're going to come across a couple of issues with this, because Fortify is going to expect that some of these views are enabled when we implement these features. Because we're doing this with inertia,
04:24
there's a slight challenge in that we need to just tweak a couple of things around. But we will get to that later. But these are all of our routes that we
04:31
need to basically send data down from our client side to register users. So for example, when we build out our registration form, all we're going to need to do is create a registration form
04:43
and then just pass this data down to Fortify. We don't need to specifically create anything. We don't need to actually create the insertion of the user or anything like that.
04:52
All of that stuff is handled by Fortify. Now speaking about that, let's go over to our application. When we did install Fortify, we got this Actions folder created and under this Fortify directory.
05:05
So these are kind of the single actions that happen when we do stuff in our application. They're not available for every single feature of Fortify. But for example, they are available for stuff
05:16
like creating a new user. So we're not really going to need to modify this code unless we want to make any changes to how we're registering users.
05:23
The point of these actions being published into our project is that if we needed to add, say, a username, we could go ahead and just modify this within the validator and we could modify this when we create a user.
05:35
So that's why these are published, so we can change them if we need to. But all of them are in there available for you to modify if you need to.
05:43
And we will be slightly modifying some of them as we go. So that is Fortify installed. Nothing much has changed, but hopefully now we
05:51
understand what this is. And now, really, once we've finished setting up the rest of our app, like our routes and stuff, we can just start sending requests down
05:59
to Fortify, which will create a user for us, and we're pretty much good to go. So very, very easy to just send requests to Fortify and all of our auth stuff is already done for us.
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.