So now we want to actually set up some routes to pages that are only available to users who are logged
in, and that's really simple to do.
First of all, what I'm going to do is create a handbook, a new handler, and I'm going to call it
func, and it'll have the receiver of Repository, as usual.
And I'm going to call it admin dashboard.
And it's a handler, so we give it the standard parameters.
And all that's going to do right now is show a simple template, OK, and the template doesn't exist,
but we'll create it in a moment.
It's going to be a really simple template for now just to make sure that things work as expected.
So let's render the template.
And the template is going to require the response writer, the pointer to the request, and we'll call
it admin dashboard page dot tempo and we'll give it an empty models template data.
OK, so that is our first step.
Now let's go create a template, so in my templates folder, I'm going to create a really simple template,
a new file, and I will call this admin.
Dashboard page, up tempo, and there it is and all I'm going to say in this is this page is secure
and we'll make a real template, a real dashboard template and dashboard admin pages in the next lecture
or two.
So let's save that.
Now, let's go back to our roots.
And here's the part where we protect our roots.
What I'm going to do is create using mux, something that's built into the router that we're using in
this package.
And it's called Muxtape Root, and it requires a pattern.
I'm going to give it a pattern of slash admin.
Anything that starts with admin will be handled by this particular function.
The root function on on the mux router and inside of that are the second parameter is itself going to
be a function and an anonymous function that takes mux, which is of type Ketut router as a parameter.
And the body of that function will be things that I want to do, routes that I want to match.
So the first thing I'm going to do before I actually add any roots to this is we're going to use this
middleware.
And if you remember, let's open up our middleware file.
We created this one, called off and all off does is to make sure that the user is authenticated.
OK, so we're going to use that middleware in this route.
And this middleware will only apply to things that are inside this Muxtape root function.
So let's use the middleware mark use of.
And now will create a new road and let's do let's do it as a get request must get and the pattern is
going to have admin pretended to it.
So what I want to add here is a route to dashboard, which will actually be a route to slash admin slash
dashboard, and that's going to use a handler.
So handlers repo and will use repo and will use the dashboard one we just created, which I believe
I called admin dashboard.
I did.
OK, so we've created this right now, so let's try it out.
Let's stop our application.
If it's running, it is.
And run it.
And first of all, we'll go to our application, make sure we're not logged in.
We're not.
And let's try going to slash admin slash dashboard.
And it takes me to the login page exactly as it should.
So let's log in admin, admin, dot com password.
Log in and now let's try going to that route again, admin dashboard.
And it shows me that she is secure.
So now we have a means of ensuring that certain routes in our application are only available to authenticated
users.
And what we need to do next is to actually build a back end that allows the property owner to look at
reservations, to cancel them, to change them, whatever it may be.
And we'll do that in the next section of the course.