1
00:00:00,000 --> 00:00:03,000
So now that we know how authentication works

2
00:00:03,000 --> 00:00:05,000
and that we got these two different parts,

3
00:00:05,000 --> 00:00:09,000
we can start implementing these flows

4
00:00:09,000 --> 00:00:12,000
into our application.

5
00:00:12,000 --> 00:00:16,000
And since this, of course, involves multiple steps,

6
00:00:16,000 --> 00:00:21,000
which are necessarily super simple to implement

7
00:00:21,000 --> 00:00:23,000
if you do it all on your own,

8
00:00:23,000 --> 00:00:25,000
it's quite common to use extra libraries

9
00:00:25,000 --> 00:00:29,000
that deal with that authentication stuff.

10
00:00:29,000 --> 00:00:33,000
And one pretty useful, relatively new,

11
00:00:33,000 --> 00:00:37,000
but popular library that you can use

12
00:00:37,000 --> 00:00:41,000
with NextJS is Lucia Auth.

13
00:00:41,000 --> 00:00:45,000
You can simply search for Lucia Auth to find its page,

14
00:00:45,000 --> 00:00:47,000
and on that page you can then, of course,

15
00:00:47,000 --> 00:00:49,000
learn all about it.

16
00:00:49,000 --> 00:00:53,000
You can use this package not just in NextJS applications,

17
00:00:53,000 --> 00:00:56,000
but also in other Node.js apps

18
00:00:56,000 --> 00:01:00,000
and actually also in Bun, Deno, and Cloudflare Workers apps.

19
00:01:01,000 --> 00:01:05,000
Now there also would be a NextAuth.js package,

20
00:01:05,000 --> 00:01:08,000
which is also pretty popular,

21
00:01:08,000 --> 00:01:12,000
but at least at the point of time where I'm recording this,

22
00:01:12,000 --> 00:01:17,000
this package doesn't work that well with the App Router.

23
00:01:17,000 --> 00:01:19,000
It has certain issues.

24
00:01:19,000 --> 00:01:23,000
The documentation, honestly, isn't great,

25
00:01:23,000 --> 00:01:26,000
and therefore, you can absolutely take a look

26
00:01:26,000 --> 00:01:28,000
at this package as well.

27
00:01:28,000 --> 00:01:30,000
It can be very useful,

28
00:01:30,000 --> 00:01:33,000
and it is built for NextJS.

29
00:01:33,000 --> 00:01:34,000
Though, it, in the end,

30
00:01:34,000 --> 00:01:39,000
also exists for other frameworks and Node.js projects now,

31
00:01:39,000 --> 00:01:41,000
but in my personal experience,

32
00:01:41,000 --> 00:01:43,000
Lucia is simply a bit more straightforward

33
00:01:43,000 --> 00:01:46,000
and frankly, easier to use.

34
00:01:46,000 --> 00:01:50,000
And therefore, I will use Lucia in this section here

35
00:01:50,000 --> 00:01:53,000
to implement authentication together with you.

36
00:01:53,000 --> 00:01:57,000
Now, to use it, we need to install it,

37
00:01:57,000 --> 00:01:59,000
and therefore, here in my project,

38
00:01:59,000 --> 00:02:02,000
I'll do that by running npm install lucia.

39
00:02:02,000 --> 00:02:05,000
And actually, I'll also install a second package

40
00:02:05,000 --> 00:02:08,000
from @lucia-auth,

41
00:02:09,000 --> 00:02:13,000
and that's the adapter-sqlite package,

42
00:02:14,000 --> 00:02:17,000
which, in the end, will then allow Lucia

43
00:02:17,000 --> 00:02:19,000
to store those sessions,

44
00:02:19,000 --> 00:02:23,000
which I mentioned in a SQLite database.

45
00:02:23,000 --> 00:02:26,000
Because I did explain that we will need to create

46
00:02:26,000 --> 00:02:29,000
and store those sessions,

47
00:02:29,000 --> 00:02:31,000
well, Lucia will create them for us,

48
00:02:31,000 --> 00:02:34,000
but we need to tell Lucia where to store them.

49
00:02:34,000 --> 00:02:36,000
And we do tell it

50
00:02:36,000 --> 00:02:39,000
to use the SQLite database we already have

51
00:02:39,000 --> 00:02:40,000
with help of this package.

52
00:02:40,000 --> 00:02:43,000
But we'll go through all the required steps

53
00:02:43,000 --> 00:02:45,000
step by step together now.

54
00:02:46,000 --> 00:02:47,000
For the moment,

55
00:02:47,000 --> 00:02:49,000
I'll just restart that development server,

56
00:02:49,000 --> 00:02:51,000
and next we're going to write some code.

