WEBVTT

1
00:00:01.039 --> 00:00:07.440
So we get some errors, for example here this error, reference error, verify user credentials

2
00:00:07.440 --> 00:00:08.600
is not defined.

3
00:00:10.080 --> 00:00:15.400
Now I actually already see where this is coming from but what you can do of course if you

4
00:00:15.400 --> 00:00:19.460
get errors like this is you can use AI for fixing them.

5
00:00:20.940 --> 00:00:26.960
Now depending on the version you're using you might have a little fix with AI button

6
00:00:26.920 --> 00:00:33.200
here already but if that's not the case you can still highlight this and you should

7
00:00:33.200 --> 00:00:36.020
get a pop-up which allows you to add this to chat.

8
00:00:37.660 --> 00:00:47.080
If you do that you can send this to the AI or say I got this error and well let the AI

9
00:00:47.080 --> 00:00:49.640
help you if you don't know what's causing this error.

10
00:00:50.360 --> 00:00:56.240
In this case the AI tells me that it appears like the verify user credentials function

11
00:00:56.260 --> 00:01:02.740
is being called but it's not defined or imported and the fix is to add the appropriate import

12
00:01:02.740 --> 00:01:04.540
so this import here.

13
00:01:06.420 --> 00:01:12.420
And therefore we can apply this and as you see the only change it makes to this file

14
00:01:12.420 --> 00:01:16.340
is here in the import statement and I'll accept this and therefore this function should

15
00:01:16.340 --> 00:01:17.100
now be available.

16
00:01:18.060 --> 00:01:23.060
So that was a quick and easy fix but it's nice to see how AI can help you with errors

17
00:01:23.060 --> 00:01:24.860
if you don't know what's wrong.

18
00:01:25.860 --> 00:01:30.920
And speaking of not knowing what's wrong we saw before in the previous lecture that

19
00:01:30.920 --> 00:01:36.900
when we created a user we got back an empty user object here in a success response and

20
00:01:36.900 --> 00:01:38.740
that doesn't make sense.

21
00:01:39.820 --> 00:01:41.840
We should get the actual user data here.

22
00:01:42.620 --> 00:01:47.880
So what we could do is manually go through the code maybe we also already know what's

23
00:01:47.880 --> 00:01:53.180
wrong but we can also copy this response here and then bring up the chat, open a new chat

24
00:01:53.140 --> 00:02:04.840
maybe and say when testing the sign up route I got back a success message but the user

25
00:02:04.840 --> 00:02:10.780
data, user object was an empty object.

26
00:02:12.080 --> 00:02:13.500
See below.

27
00:02:15.480 --> 00:02:19.140
Why do I get this response?

28
00:02:20.460 --> 00:02:22.320
And now I'll bring in some extra context.

29
00:02:22.600 --> 00:02:27.480
The user's controller file is already there but maybe it's also helpful to have access

30
00:02:27.480 --> 00:02:38.520
to the model so I'll add this file here and I'll also add the user routes so that I make

31
00:02:38.520 --> 00:02:43.820
sure that the AI will take a look at all these files which hopefully help it understand what

32
00:02:43.820 --> 00:02:44.640
the problem is.

33
00:02:47.220 --> 00:02:54.320
So it takes a look at the code and it correctly identifies that the create user function is

34
00:02:54.320 --> 00:03:01.420
an asynchronous function hence it returns a so-called promise in JavaScript and you

35
00:03:01.420 --> 00:03:06.940
need to await this promise in order to get the actual data yielded by the promise and

36
00:03:06.940 --> 00:03:08.940
we did not do this yet.

37
00:03:09.580 --> 00:03:15.420
So to fix this we need to make changes to the sign up function and await the result

38
00:03:15.460 --> 00:03:16.360
of create user.

39
00:03:18.619 --> 00:03:26.120
So in the user's controller JS file we must add await in front of create user and async

40
00:03:26.120 --> 00:03:28.080
in front of the function keyword here.

41
00:03:29.899 --> 00:03:36.540
So we could do this manually or we click apply and it changes this part here and adds the

42
00:03:36.540 --> 00:03:43.440
async keyword as I mentioned and it changes this part down here and adds the await keyword

43
00:03:44.340 --> 00:03:48.960
and that's exactly what needs to be done so I'll accept this, save this file and we

44
00:03:48.960 --> 00:03:49.780
should be good.

45
00:03:51.680 --> 00:03:57.340
With that if we now close this and if we create another user it should work.

46
00:03:58.380 --> 00:04:05.120
Now if I try to send the same pieces of data especially an email address which was already

47
00:04:05.120 --> 00:04:12.560
used I should be getting an error and I do but if I use a different email address that

48
00:04:12.500 --> 00:04:17.820
should now work again and now I do get back these user details so that is working now.

49
00:04:20.440 --> 00:04:25.260
And for logging in we can give this another try, this now also works.

50
00:04:25.760 --> 00:04:34.560
If I however use an email address that doesn't exist I get an error or if I use an invalid

51
00:04:34.560 --> 00:04:37.360
password I also get an error.

52
00:04:37.640 --> 00:04:41.240
So it's really just the correct credentials that get me logged in.

53
00:04:42.440 --> 00:04:47.900
And that's another huge step forward of course and as you can see we have a nice mixture

54
00:04:47.900 --> 00:04:50.760
of knowledge and AI usage here.

55
00:04:51.860 --> 00:04:56.600
And of course I'm not super fast here because I'm explaining a lot but you could probably

56
00:04:56.600 --> 00:05:01.840
see how fast you could be if you would just be using AI, hitting tab, using chat, using

57
00:05:01.800 --> 00:05:06.180
your knowledge and you would combine all these things to build this kind of application.

