1
00:00:02,000 --> 00:00:03,000
As I mentioned in the last lecture,

2
00:00:03,000 --> 00:00:07,000
we don't need to build everything from scratch.

3
00:00:07,000 --> 00:00:10,000
Instead there is a package, the NextAuth package

4
00:00:10,000 --> 00:00:14,000
which we can use for implementing authentication.

5
00:00:14,000 --> 00:00:18,000
Now the NextAuth package makes adding authentication

6
00:00:18,000 --> 00:00:21,000
to your next application super, super simple.

7
00:00:21,000 --> 00:00:24,000
And it actually supports a broad variety

8
00:00:24,000 --> 00:00:27,000
of authentication for writers.

9
00:00:27,000 --> 00:00:30,000
So you can't just go with your own email

10
00:00:30,000 --> 00:00:32,000
and password combination.

11
00:00:32,000 --> 00:00:36,000
You can also easily add Sign In with Google or Facebook

12
00:00:36,000 --> 00:00:39,000
or Apple or whatever you want with NextAuth.

13
00:00:40,000 --> 00:00:43,000
The documentation of course is the place to go.

14
00:00:43,000 --> 00:00:46,000
And there, if you click on authentication providers

15
00:00:46,000 --> 00:00:49,000
you'll see a list of supported providers

16
00:00:49,000 --> 00:00:50,000
and if you click on one, you'll learn

17
00:00:50,000 --> 00:00:54,000
how to implement authentication with that provider.

18
00:00:54,000 --> 00:00:58,000
So that is something you absolutely can do.

19
00:00:58,000 --> 00:01:00,000
Now here in this module

20
00:01:00,000 --> 00:01:03,000
we will not use one of those providers though

21
00:01:03,000 --> 00:01:05,000
but instead we will build it from scratch

22
00:01:05,000 --> 00:01:08,000
with our own email password combination

23
00:01:08,000 --> 00:01:12,000
stored in our own database so that we can really see

24
00:01:12,000 --> 00:01:17,000
the complete authentication flow in greatest detail.

25
00:01:17,000 --> 00:01:20,000
Now therefore that is the package we are going to use

26
00:01:20,000 --> 00:01:22,000
and hence to get started,

27
00:01:22,000 --> 00:01:26,000
what we'll do is we'll first of all install NextAuth.

28
00:01:26,000 --> 00:01:27,000
So in our project folder,

29
00:01:27,000 --> 00:01:32,000
or quits to dev server and NPM, install NextAuth.

30
00:01:32,000 --> 00:01:36,000
To install this NextAuth package next to dash-auth.

31
00:01:36,000 --> 00:01:39,000
We'll install that and the NextAuth package

32
00:01:39,000 --> 00:01:44,000
has both server-side and client-side capabilities.

33
00:01:44,000 --> 00:01:47,000
We'll be able to use it on some API routes

34
00:01:47,000 --> 00:01:50,000
to verify if a user is logged in and we'll be able

35
00:01:50,000 --> 00:01:53,000
to use it in our components to do the same.

36
00:01:53,000 --> 00:01:56,000
Because of course the answer to the question

37
00:01:56,000 --> 00:01:58,000
whether a user is logged in

38
00:01:58,000 --> 00:02:02,000
and authenticated is not just needed on protected resources

39
00:02:02,000 --> 00:02:06,000
on the server-side, so in our API routes

40
00:02:06,000 --> 00:02:08,000
but also in our client-side components.

41
00:02:08,000 --> 00:02:13,000
There we also might want to show a different user interface

42
00:02:13,000 --> 00:02:17,000
based on whether a user is authenticated or not.

43
00:02:17,000 --> 00:02:20,000
And NextAuth will allow us to do both

44
00:02:20,000 --> 00:02:23,000
server-side and client-side validation.

45
00:02:23,000 --> 00:02:27,000
It will also help us with generating those Auth Tokens.

46
00:02:27,000 --> 00:02:29,000
Those JSON Web Tokens.

47
00:02:29,000 --> 00:02:31,000
One thing it will not do though

48
00:02:31,000 --> 00:02:35,000
is manage user creation for us.

49
00:02:35,000 --> 00:02:38,000
We need to bring our own logic for this.

50
00:02:38,000 --> 00:02:41,000
It does support various databases

51
00:02:41,000 --> 00:02:45,000
but mostly for other authentication methods.

52
00:02:45,000 --> 00:02:48,000
And when it comes to having our own user accounts

53
00:02:48,000 --> 00:02:49,000
then we need to bring our own

54
00:02:49,000 --> 00:02:54,000
signup API route and our own user verification logic.

55
00:02:56,000 --> 00:02:58,000
But that's exactly what we're going to build

56
00:02:58,000 --> 00:03:00,000
over the next lectures now

57
00:03:00,000 --> 00:03:02,000
and what we're going to explore there.

