As I mentioned in the last lecture,
we don't need to build everything from scratch.
Instead there is a package, the NextAuth package
which we can use for implementing authentication.
Now the NextAuth package makes adding authentication
to your next application super, super simple.
And it actually supports a broad variety
of authentication for writers.
So you can't just go with your own email
and password combination.
You can also easily add Sign In with Google or Facebook
or Apple or whatever you want with NextAuth.
The documentation of course is the place to go.
And there, if you click on authentication providers
you'll see a list of supported providers
and if you click on one, you'll learn
how to implement authentication with that provider.
So that is something you absolutely can do.
Now here in this module
we will not use one of those providers though
but instead we will build it from scratch
with our own email password combination
stored in our own database so that we can really see
the complete authentication flow in greatest detail.
Now therefore that is the package we are going to use
and hence to get started,
what we'll do is we'll first of all install NextAuth.
So in our project folder,
or quits to dev server and NPM, install NextAuth.
To install this NextAuth package next to dash-auth.
We'll install that and the NextAuth package
has both server-side and client-side capabilities.
We'll be able to use it on some API routes
to verify if a user is logged in and we'll be able
to use it in our components to do the same.
Because of course the answer to the question
whether a user is logged in
and authenticated is not just needed on protected resources
on the server-side, so in our API routes
but also in our client-side components.
There we also might want to show a different user interface
based on whether a user is authenticated or not.
And NextAuth will allow us to do both
server-side and client-side validation.
It will also help us with generating those Auth Tokens.
Those JSON Web Tokens.
One thing it will not do though
is manage user creation for us.
We need to bring our own logic for this.
It does support various databases
but mostly for other authentication methods.
And when it comes to having our own user accounts
then we need to bring our own
signup API route and our own user verification logic.
But that's exactly what we're going to build
over the next lectures now
and what we're going to explore there.