So now that we know how authentication works
and that we got these two different parts,
we can start implementing these flows
into our application.
And since this, of course, involves multiple steps,
which are necessarily super simple to implement
if you do it all on your own,
it's quite common to use extra libraries
that deal with that authentication stuff.
And one pretty useful, relatively new,
but popular library that you can use
with NextJS is Lucia Auth.
You can simply search for Lucia Auth to find its page,
and on that page you can then, of course,
learn all about it.
You can use this package not just in NextJS applications,
but also in other Node.js apps
and actually also in Bun, Deno, and Cloudflare Workers apps.
Now there also would be a NextAuth.js package,
which is also pretty popular,
but at least at the point of time where I'm recording this,
this package doesn't work that well with the App Router.
It has certain issues.
The documentation, honestly, isn't great,
and therefore, you can absolutely take a look
at this package as well.
It can be very useful,
and it is built for NextJS.
Though, it, in the end,
also exists for other frameworks and Node.js projects now,
but in my personal experience,
Lucia is simply a bit more straightforward
and frankly, easier to use.
And therefore, I will use Lucia in this section here
to implement authentication together with you.
Now, to use it, we need to install it,
and therefore, here in my project,
I'll do that by running npm install lucia.
And actually, I'll also install a second package
from @lucia-auth,
and that's the adapter-sqlite package,
which, in the end, will then allow Lucia
to store those sessions,
which I mentioned in a SQLite database.
Because I did explain that we will need to create
and store those sessions,
well, Lucia will create them for us,
but we need to tell Lucia where to store them.
And we do tell it
to use the SQLite database we already have
with help of this package.
But we'll go through all the required steps
step by step together now.
For the moment,
I'll just restart that development server,
and next we're going to write some code.