1
00:00:00,270 --> 00:00:06,689
Our initial functionality works just fine, but when it comes to verification token.

2
00:00:07,620 --> 00:00:11,670
Setting it up as fake token production is kind of silly.

3
00:00:12,180 --> 00:00:22,050
What you want is unique token for each user, so user registers he or she gets that unique token and

4
00:00:22,050 --> 00:00:23,940
then will proceed to the next steps.

5
00:00:24,600 --> 00:00:27,390
At the moment, all of them will have this fake token.

6
00:00:27,750 --> 00:00:31,080
Now there's various ways how we can set this up.

7
00:00:31,680 --> 00:00:38,240
We can use maybe a unique I.D. library like you, I.D. and stuff along those lines.

8
00:00:38,250 --> 00:00:45,060
But there's also a nifty are set up, at least in my opinion, where we can use a crypto library which

9
00:00:45,060 --> 00:00:51,630
is actually built into a node so we don't need to install anything extra or anything like that.

10
00:00:52,020 --> 00:00:54,600
So let's go above, what do we have right now?

11
00:00:55,050 --> 00:01:01,920
Batch cookies and right after that, we're going to go with Konst Crypto, and that is equal to require.

12
00:01:02,220 --> 00:01:06,570
So Let just required a package and we're looking for a crypto package.

13
00:01:07,080 --> 00:01:07,860
I must say.

14
00:01:08,740 --> 00:01:14,200
Let's keep on scrolling and what we're looking for is this verification token, and now instead of this

15
00:01:14,200 --> 00:01:16,810
fake token, here's what we're going to do.

16
00:01:17,350 --> 00:01:18,820
I'm going to remove everything.

17
00:01:19,150 --> 00:01:20,380
We're going to go with crypto.

18
00:01:21,010 --> 00:01:26,290
So that's what we're getting back from the library and the method name is random bytes.

19
00:01:27,130 --> 00:01:34,280
So essentially, this is going to create a buffer with around them bytes and you can pass here the number.

20
00:01:34,480 --> 00:01:36,310
And in my case, I'm going to go with 40.

21
00:01:36,880 --> 00:01:43,480
Now, since this is a buffer, I actually want to turn it into a string on a buffer.

22
00:01:43,490 --> 00:01:50,350
We have this method called two string, which effectively does turn it into a string, and by default,

23
00:01:50,350 --> 00:01:52,510
the encoding is going to be UTF eight.

24
00:01:52,990 --> 00:01:57,880
But what we want to set it up as hex where effectively.

25
00:01:58,930 --> 00:02:04,120
Each bite is going to be encoded as two hexadecimal characters.

26
00:02:04,480 --> 00:02:08,199
Now I understand that this is kind of a lot at the end of the day.

27
00:02:08,620 --> 00:02:13,990
You need to understand or just get this random big string value.

28
00:02:14,440 --> 00:02:15,430
So let's try to do that.

29
00:02:15,730 --> 00:02:21,100
We're going to go with crypto random byte to string its passed in the Hex.

30
00:02:21,820 --> 00:02:27,820
And then let's say it again, since we're still testing everything, like I said, she's going to be

31
00:02:27,820 --> 00:02:29,820
a little bit annoying where you need to go back.

32
00:02:29,830 --> 00:02:31,060
At least I'm going to do that.

33
00:02:31,750 --> 00:02:38,920
I'm going to remove Anna, and let's try to register one more time and you'll see how the value actually

34
00:02:39,310 --> 00:02:41,860
will be that random bytes one.

35
00:02:42,340 --> 00:02:43,300
So it's four more.

36
00:02:43,990 --> 00:02:50,440
Now we want to navigate back to our postman and instead of register, or I'm sorry, instead of login,

37
00:02:51,040 --> 00:02:54,550
we'll go with the register again, send back and now check it out.

38
00:02:55,180 --> 00:03:00,490
So we have this random bytes value and this is exactly what we're looking for.

39
00:03:00,670 --> 00:03:07,810
We have this random string, which we're going to use in order to verify the email.

