1
00:00:00,180 --> 00:00:03,990
All right, and essentially why we're getting that error in the previous video.

2
00:00:04,050 --> 00:00:06,570
Remember before we comment about the code?

3
00:00:07,550 --> 00:00:13,670
And before we take a look at the functionality that caused that, let's also discuss the fact that not

4
00:00:13,670 --> 00:00:17,150
every method will trigger this hook.

5
00:00:17,820 --> 00:00:23,390
This is very, very important where if, for example, if I were to go with find one and update, everything

6
00:00:23,390 --> 00:00:24,470
would have worked out fine.

7
00:00:25,510 --> 00:00:31,700
We basically would have bypassed the stock and we would be on our way already, or I purposely wanted

8
00:00:31,730 --> 00:00:36,850
use their debt save to showcase that there's going to be some methods that will trigger the silk.

9
00:00:37,830 --> 00:00:42,930
And in the process, we need to take a look at what is the approach, if that is the case.

10
00:00:43,410 --> 00:00:45,390
Essentially, that is the point of this video.

11
00:00:45,660 --> 00:00:50,670
So hopefully that is clear and that's why we purposely went with this user.

12
00:00:50,670 --> 00:00:54,510
That same now next why there was this error.

13
00:00:54,630 --> 00:01:00,210
Well, because if we take a look at the script hash out, we're looking for this that password.

14
00:01:00,780 --> 00:01:09,540
Now remember, like we already previously talked about in the user, select password is equal to false.

15
00:01:09,900 --> 00:01:14,910
And in the off controller, when we use this fine one, we don't return the password.

16
00:01:15,420 --> 00:01:19,590
So when I go here with users, save will trigger the hook.

17
00:01:19,890 --> 00:01:21,270
Now what are we doing in the hook?

18
00:01:21,900 --> 00:01:25,560
We have b crypt hash and then we're looking for this dot password.

19
00:01:26,340 --> 00:01:34,020
But since we have set up the password equal to select false, therefore this one will be undefined.

20
00:01:34,620 --> 00:01:38,460
And technically you can look at it and you're like, OK, well, we'll do the same thing.

21
00:01:38,820 --> 00:01:42,330
We're going to go over here with select and add the password.

22
00:01:43,190 --> 00:01:49,550
But what we also need to understand that if that is going to be the case, why do you think it's going

23
00:01:49,550 --> 00:01:50,300
to be a result?

24
00:01:51,140 --> 00:01:58,190
So if actually I do have the password, essentially if I go with that select and then plus the password.

25
00:01:58,670 --> 00:02:05,990
And if I hash it, don't you think that I'll essentially hash the password that is already hashed and

26
00:02:05,990 --> 00:02:13,070
in the process, my log in is going to be messed up because now when I'm trying to log in with secret,

27
00:02:13,070 --> 00:02:18,290
which essentially is my password now, it won't match to the hashed value in the database.

28
00:02:18,590 --> 00:02:23,360
And I'm not going to show you the example because it will take some time to set this one up.

29
00:02:23,750 --> 00:02:31,010
But yes, what you need to keep in mind if you go here and you add this password and essentially this

30
00:02:31,010 --> 00:02:37,970
functionality will work as expected that as a result, your in functionality won't work because in that

31
00:02:37,970 --> 00:02:46,250
case, you'll hash the password for the second time that is already stored and hashed in a database.

32
00:02:46,610 --> 00:02:49,460
Now what is the solution for both of the scenarios?

33
00:02:49,820 --> 00:02:57,080
Well, the solution is following where we can go with this and then modify paths so we can check which

34
00:02:57,080 --> 00:03:00,800
paths are we modifying and what supernovas we can look for.

35
00:03:00,800 --> 00:03:01,520
Specific one.

36
00:03:01,970 --> 00:03:09,830
And if we're not modifying the password, which our route is not doing, essentially we want to modify

37
00:03:09,830 --> 00:03:11,900
everything else but the password.

38
00:03:12,200 --> 00:03:16,190
Then we simply return and in the process isn't going to do two things.

39
00:03:16,190 --> 00:03:20,390
First, where we won't get this error when the password is not provided.

40
00:03:20,660 --> 00:03:28,790
And second, if this not password actually exists in the instance, then you won't hash it for a second

41
00:03:28,790 --> 00:03:29,060
time.

42
00:03:29,300 --> 00:03:32,630
Hopefully, this makes sense and now not set it up in the user dress.

43
00:03:32,960 --> 00:03:34,100
Let's navigate there.

44
00:03:34,370 --> 00:03:39,560
I mean, at the moment, I have commented them out and what we simply want to do is go and log.

45
00:03:40,620 --> 00:03:48,090
And we can go off this dot and then we have this method that returns all the paths that we're modifying.

46
00:03:48,540 --> 00:03:52,950
So let's invoke it and let's go to the postman and let's send one more time.

47
00:03:53,340 --> 00:03:55,950
So in this case, I'm just going to send it as it is.

48
00:03:56,280 --> 00:04:01,680
And what you'll notice that at the moment, we're technically have an empty array, correct, so we're

49
00:04:01,680 --> 00:04:03,180
not modifying anything.

50
00:04:03,480 --> 00:04:10,300
But if I go here and then say that name again is going to be John, but notice now I have name here.

51
00:04:10,530 --> 00:04:13,380
And effectively, this function just returns nicely.

52
00:04:13,620 --> 00:04:15,720
Which values are we updating?

53
00:04:16,079 --> 00:04:23,160
And hopefully you can clearly see that it only returns values that are different to the ones that we

54
00:04:23,160 --> 00:04:24,990
already have in the database.

55
00:04:25,200 --> 00:04:26,370
So hopefully that is square.

56
00:04:26,790 --> 00:04:33,900
And like I said, there's also this there's not and then is modified so I can check for specific path.

57
00:04:34,690 --> 00:04:39,670
And if I'm modifying that one, well, I can do something based on that.

58
00:04:40,330 --> 00:04:45,790
And in our case, we actually will look for is modified land password.

59
00:04:46,600 --> 00:04:52,520
And if we're not modifying the password, well, I don't want to do anything there because you're in

60
00:04:52,520 --> 00:04:52,750
now.

61
00:04:52,760 --> 00:04:56,560
If you took mine, of course, that if we're modifying the password, then we're setting everything

62
00:04:56,830 --> 00:04:58,150
from scratch anyway.

63
00:04:58,570 --> 00:05:04,210
But in this case, since I don't want to touch the password, I don't want to get the error or I don't

64
00:05:04,210 --> 00:05:08,860
want to hash it for the second time, and therefore I just want to return from the function.

65
00:05:08,950 --> 00:05:10,780
So let me go back to the user one.

66
00:05:11,050 --> 00:05:12,040
I'm not going to log it.

67
00:05:12,230 --> 00:05:14,530
I mean, if you want, you can definitely do so.

68
00:05:14,710 --> 00:05:16,600
In my case, I'm just going to set up deconditioned.

69
00:05:16,610 --> 00:05:24,190
First of all, I'll comment out of this one over here and I'll say, if this and then that and is modified.

70
00:05:24,460 --> 00:05:31,300
So if I'm not modifying which field, well, the password field, if we're not modifying that, then

71
00:05:31,300 --> 00:05:33,850
I want to go with a return over here.

72
00:05:34,260 --> 00:05:40,720
Then we can uncomment the previous set up because we will use it once we save.

73
00:05:41,290 --> 00:05:48,400
And then if I go back to the postman and if I try to send it, you'll notice that everything will work

74
00:05:48,400 --> 00:05:49,330
as expected.

75
00:05:49,480 --> 00:05:56,890
Can I send it and I get back beta and yes, when we're talking about of the register functionality.

76
00:05:57,100 --> 00:06:01,630
So essentially, when we registered user, this will be still correct.

77
00:06:02,320 --> 00:06:06,100
Where we'll still hash the password as we should.

78
00:06:06,610 --> 00:06:11,110
And once we have this in place now, we're finally ready for the front that.

