Now for this course section here,
I did prepare a demo project,
a demo project which will help us
dive into these key aspects that make up authentication.
You'll find it attached, and as always,
you should download and extract it
and then move it somewhere on your system
where it can be stored.
And then once you are in there, open that built-in terminal.
And first of all,
run npm install to install all the dependencies
that are part of this project
because I pre-added some dependencies for you
and these are all the dependencies we already know
from earlier course sections.
Nothing fancy here.
And there actually also aren't any fancy surprises
in the other files.
In app.js, we do some typical initialization work,
setting the view engine,
and then making sure incoming request bodies are parsed,
serving static content, registering some routes,
and having this generic error handler here
to handle errors that might occur.
And then I'm also connecting to a database.
And then once this succeeded,
I'm starting to listen on port 3000
to spin up that web server.
Now, one word about parsing incoming request bodies.
Here, I'm not parsing for JSON content.
In the last section,
we learned about Ajax requests and JSON data.
Because here in this demo project,
we won't be sending any Ajax requests.
Not because we couldn't do that with authentication,
we absolutely could,
but simply because it's not the focus here
and the traditional approach of sending requests,
so letting the browser handle all of that
works just fine in this course section here.
So therefore, we just parse
these URL-encoded request bodies,
so data that's coming from form submissions
directly handled by the browser.
Then in the routes folder,
I got a demo.js file with some dummy routes prepared,
basically routes for loading the signup and login pages,
for then handling the post signup and login requests
once these signup and login forms will be submitted,
then a route for loading some admin page,
and then also a logout page to which I'll come back later.
I'll come back to all these routes later to be precise.
Now, some of these routes render templates
and you find those in the views folder.
I got some error templates.
The 401 template is one I'll come back to later.
That is a template we'll show
if a user tries to access a page
where he or she is not authenticated for.
Again, I'll come back to that later.
And then I got the signup and login pages
where I render some forms.
Nothing too fancy here.
These forms then send their post requests
to /login or /signup.
And I got a welcome page and then an admin page,
which we will later lock down
so that you're not able to view it.
Initially, you will be,
but later we'll lock this down
and ensure that only logged in users
will be able to access it.
Last but not least,
I got some styles here in the public folder.
And then in the data folder,
I got my database connection code.
Basically, also the same code we used before in the course.
So really, nothing new here.
And therefore, you should be able to start your server,
just make sure that your database is up and running
either because you started it manually
or because you have that service,
that MongoDB service running in the background.
And here I am again using MongoDB.
Of course, this all here would also work with SQL.
It's not MongoDB-specific.
I'm just sticking to it
because we've used it over the last sections.
And hence, now we can run npm start
and this will then start up this node server.
Once it is up and running,
you can visit local host 3000
and there you've got a navigation bar
where you can visit the different pages.
For the moment, that includes the admin page.
You can just access it just fine initially.
We'll change this later.
And the logout button won't do anything right now.
But that's now our starting project.
And in this project,
we're now going to start on this signup page
and we'll make sure that users can actually create accounts.