1
00:00:00,360 --> 00:00:00,860
Beautiful.

2
00:00:01,200 --> 00:00:10,170
And with all of this in place now, I can finally send verification link to our user and we'll do that

3
00:00:10,170 --> 00:00:11,160
in multiple steps.

4
00:00:11,170 --> 00:00:19,680
First, we will refactor, send email, Venmo, set up, send verification, email and once we're done

5
00:00:19,680 --> 00:00:25,530
with that, then we are going to pass the arguments from the register.

6
00:00:26,100 --> 00:00:28,170
And lastly, send a link.

7
00:00:28,590 --> 00:00:34,950
Now, as always, I will start by basically cleaning out my database just so it's easier for me on the

8
00:00:34,950 --> 00:00:35,400
front then.

9
00:00:35,790 --> 00:00:39,150
Now I'm not going to send a few emails right now.

10
00:00:39,150 --> 00:00:45,330
I'm just going to set up everything and we'll send one and see if everything works, basically.

11
00:00:45,630 --> 00:00:50,220
I don't want to do this step by step where we add a little bit of code and then I send because.

12
00:00:51,390 --> 00:00:55,560
Essentially, I don't want to keep on the leading views there or creating ones from the scratch.

13
00:00:55,920 --> 00:00:58,950
Therefore, just please be vigilant for what's happening.

14
00:00:59,370 --> 00:01:06,030
So let's go back first to our application and I want to go to send sent email.

15
00:01:06,630 --> 00:01:07,680
And let's take a look.

16
00:01:07,710 --> 00:01:11,100
So here I have this mailer.

17
00:01:11,460 --> 00:01:12,570
Create transport.

18
00:01:12,690 --> 00:01:13,110
Correct.

19
00:01:13,530 --> 00:01:14,790
Now what am I passing in?

20
00:01:15,270 --> 00:01:18,390
I'm passing in some kind of config object.

21
00:01:18,570 --> 00:01:18,930
Correct.

22
00:01:19,410 --> 00:01:25,200
So wouldn't it be nicer if we would just sit that object in a separate file?

23
00:01:25,800 --> 00:01:30,210
And this is going to make the send emails slimmer.

24
00:01:30,660 --> 00:01:37,860
And also keep in mind that yes, normally if you're using, for example, SendGrid, you'll want to

25
00:01:37,860 --> 00:01:40,320
set up these values being data entry.

26
00:01:40,530 --> 00:01:44,220
Again, this is just for testing, so I'm not going to worry about that.

27
00:01:44,670 --> 00:01:50,490
And now I want to navigate, you know, mailer config want to set up here.

28
00:01:50,490 --> 00:01:53,250
Module exports are set.

29
00:01:53,250 --> 00:02:00,780
I'm just going to export the object that I'm using back in sent email instead of passing in the entire

30
00:02:00,780 --> 00:02:01,170
object.

31
00:02:01,500 --> 00:02:07,480
I'll cut it out and I'll set it equal in my export and mine.

32
00:02:07,500 --> 00:02:14,460
Once I have a list in place, I can go back to your sending email and we can just import correct and

33
00:02:14,460 --> 00:02:18,010
come up with whatever name you want, since we're exporting as default anyway.

34
00:02:18,030 --> 00:02:24,420
So let's go here const node mailer and I'm going to call this config is equal to.

35
00:02:24,720 --> 00:02:28,380
Now we just need to look for the file that's right next to us.

36
00:02:28,860 --> 00:02:32,940
So look for node mailer config and where we create to transport.

37
00:02:32,940 --> 00:02:35,160
What do we want or do we want to Facetune?

38
00:02:35,580 --> 00:02:36,840
So that's number one.

39
00:02:37,380 --> 00:02:45,330
Second, like I said, since we'll use this functionality, we send email functionality in send reset

40
00:02:45,330 --> 00:02:48,840
password as well as send verification email.

41
00:02:49,860 --> 00:02:57,780
It would make sense if we add here, argument, basically who's going to get the email so to what is

42
00:02:57,780 --> 00:03:03,630
going to be the subject, as well as what is going to be the text that we're sending back whorish the

43
00:03:03,630 --> 00:03:09,900
amount because keep in mind that each user is going to get that unique link.

44
00:03:10,260 --> 00:03:10,680
Correct.

45
00:03:11,070 --> 00:03:16,980
So let's go up here and we'll just say that we'll be looking for three things we're going to be looking

46
00:03:16,980 --> 00:03:17,370
for.

47
00:03:17,460 --> 00:03:18,510
Two parameter.

48
00:03:19,450 --> 00:03:28,060
As well as subject parameter and HD ammo, now, as always, it's my preference to set it up as an object.

49
00:03:28,060 --> 00:03:30,700
So that way I don't need to worry about the order.

50
00:03:31,210 --> 00:03:33,670
If you prefer just setting them up one by one.

51
00:03:34,510 --> 00:03:36,160
That is really up to you.

52
00:03:36,700 --> 00:03:42,910
As far as from again, this is the case where you can hard code that in data entry and then just use

53
00:03:42,910 --> 00:03:43,000
it.

54
00:03:43,510 --> 00:03:45,420
In my case, I'm just going to use it here.

55
00:03:45,640 --> 00:03:50,980
More, say Coding Addict, and as far as the email is, just going to stay the same.

56
00:03:51,310 --> 00:03:55,990
But this is going to be the value that shows the sender address, correct?

57
00:03:56,620 --> 00:03:59,230
Now, for the rest of them, what are we going to do?

58
00:03:59,710 --> 00:04:07,690
Well, we use the fact that in JavaScript, if the key name actually is the same as the variable name,

59
00:04:07,930 --> 00:04:15,340
which is going to be our parameter, you simply can go to one subject and an HMO.

60
00:04:15,820 --> 00:04:22,450
Effectively, what I'm doing right now, I'm saying that whatever values I'll pass in over here will

61
00:04:22,450 --> 00:04:25,900
be used when I'm sending the email, hopefully back to square.

62
00:04:26,290 --> 00:04:33,400
And also, we need to keep in mind one thing where since this is async, we are returning a promise

63
00:04:33,400 --> 00:04:34,060
regardless.

64
00:04:34,510 --> 00:04:36,100
So we don't need to set up here.

65
00:04:36,100 --> 00:04:40,720
A wait effectively is going to work if we just go here with return.

66
00:04:41,200 --> 00:04:48,280
Now, if you want to test that out right now in the register, you can definitely do so and just double

67
00:04:48,280 --> 00:04:49,240
check whatever works.

68
00:04:49,540 --> 00:04:54,430
Just keep in mind that now you need to start passing those values when it comes to true subject and

69
00:04:54,430 --> 00:04:54,790
all that.

70
00:04:55,330 --> 00:05:02,770
But in my case, what I'm going to do, I will set up the send verification email because, like I said,

71
00:05:02,770 --> 00:05:07,180
I want to re-use this email also in the password one.

72
00:05:07,600 --> 00:05:14,200
So we need to somehow figure out how we can pass those values from the send verification email.

73
00:05:14,320 --> 00:05:15,430
So let's navigate here.

74
00:05:16,120 --> 00:05:22,990
And first of all, I do is grab that, send the emails or send email is equal to choir.

75
00:05:23,410 --> 00:05:26,320
And then let's look for send email.

76
00:05:26,710 --> 00:05:32,860
Once we have a verse in place or we want to do is create a function.

77
00:05:33,070 --> 00:05:40,660
So instead of calling send email directly in register, we will call send verification email and we'll

78
00:05:40,660 --> 00:05:43,420
return the send email from that function.

79
00:05:44,300 --> 00:05:49,580
And again, it's going to be a cinch, so we don't need to await instead of the function body scenes

80
00:05:49,580 --> 00:05:51,180
at the end of it, if you remember.

81
00:05:51,560 --> 00:05:55,760
And here we're sticking to waiting for an hour anyway, so it doesn't really matter.

82
00:05:56,240 --> 00:06:01,430
So let me just actually save some stuff and let's come up with that function that we're going to be

83
00:06:01,430 --> 00:06:03,520
exporting from this file.

84
00:06:03,530 --> 00:06:12,380
So let's say here, send verification email again is going to be a sync, for starters, and it's going

85
00:06:12,380 --> 00:06:14,780
to be looking for following things.

86
00:06:15,720 --> 00:06:20,580
It will need a name, so user name will also need a user email.

87
00:06:21,100 --> 00:06:23,610
Remember those things we do have and register correct?

88
00:06:23,970 --> 00:06:26,190
We want a verification token.

89
00:06:26,640 --> 00:06:28,080
That's extremely important.

90
00:06:28,290 --> 00:06:34,320
Otherwise, whatever we are about to set up, it's not going to really make sense as well as origin.

91
00:06:34,920 --> 00:06:38,370
And I fully understand that this might not make sense right now.

92
00:06:38,370 --> 00:06:44,340
And therefore, I will spam an entire video showing you multiple options that you have for origin.

93
00:06:44,340 --> 00:06:46,560
But long story short.

94
00:06:47,280 --> 00:06:56,490
Well, this is going to be the URL for the frontend, whether that is 3000 on our local setup or it

95
00:06:56,490 --> 00:06:57,720
is the production one.

96
00:06:58,560 --> 00:07:04,890
So just keep that in mind, that is the URL and that as far as the functionality for now, here's what

97
00:07:04,890 --> 00:07:05,430
I want to do.

98
00:07:06,060 --> 00:07:07,590
I simply want to return.

99
00:07:08,160 --> 00:07:09,150
Send the email again.

100
00:07:09,160 --> 00:07:14,790
This is this thing so we can simply return, send email since we are returning any promise at the end

101
00:07:14,790 --> 00:07:15,510
of the day anyway.

102
00:07:15,960 --> 00:07:19,560
And then remember when it comes to send email?

103
00:07:19,980 --> 00:07:20,820
What do we want?

104
00:07:21,180 --> 00:07:26,250
Well, we want to parameter and that is where we are going to be sending.

105
00:07:26,550 --> 00:07:26,970
Correct.

106
00:07:27,240 --> 00:07:31,350
So I'll set you equal to what all that is going to be equal to an email.

107
00:07:31,740 --> 00:07:33,000
The user email, correct.

108
00:07:33,180 --> 00:07:40,520
So we go here with email, then as far as the subject, well, let's come up with the value of, say,

109
00:07:40,530 --> 00:07:44,490
subject and we'll go with email confirmation.

110
00:07:44,760 --> 00:07:50,970
Now again, why we're passing subject as an argument because like I already said quite a few times,

111
00:07:51,120 --> 00:07:52,860
we will re-use this functionality.

112
00:07:52,920 --> 00:07:57,570
So that's why it's important for us to set it up here as a parameter.

113
00:07:57,990 --> 00:08:01,620
So in here, let's say email confirmation.

114
00:08:02,580 --> 00:08:05,830
One, we also want to pass the HMO, correct.

115
00:08:06,240 --> 00:08:08,010
So we're going to go here with the amount.

116
00:08:08,550 --> 00:08:14,730
And before we do anything, let's set up the message and I'm going to do that above where we're going

117
00:08:14,730 --> 00:08:16,170
to go with the message.

118
00:08:16,650 --> 00:08:23,100
And since it's going to be announced, the amount of right away set up as a paragraph here, I'll close

119
00:08:23,100 --> 00:08:26,700
it and we're not going to set up the link yet.

120
00:08:27,150 --> 00:08:30,030
But let just add a text and effectively it's going to be.

121
00:08:30,180 --> 00:08:33,929
Please confirm your email by clicking on the following link.

122
00:08:33,960 --> 00:08:37,590
Again, we're not going to add a actual link yet.

123
00:08:37,950 --> 00:08:46,860
For now, we just want a text, so I have my argument and I'll just hardcoded equal to some kind of

124
00:08:46,860 --> 00:08:48,240
message on this case.

125
00:08:48,240 --> 00:08:52,620
I'm going to go with writing for here, and let's just say hello.

126
00:08:52,950 --> 00:08:54,460
Now I'll use the name.

127
00:08:54,480 --> 00:08:56,280
That's why I'm using temperatures here.

128
00:08:56,520 --> 00:08:59,730
So this is going to be the user name that we're sending.

129
00:09:00,120 --> 00:09:01,620
So let's go here with the name.

130
00:09:02,220 --> 00:09:08,130
I'll close the heading for here and in the next line, I want to send the message.

131
00:09:08,400 --> 00:09:09,480
So here's what I want to do.

132
00:09:09,480 --> 00:09:18,150
I want to share it just so I get the formatting correct and then I want to access that message and eventually

133
00:09:18,150 --> 00:09:20,850
there is going to be a confirmation link.

134
00:09:21,270 --> 00:09:25,440
So these are the things that we currently have.

135
00:09:25,950 --> 00:09:30,090
We have name, email and verification token as well as origin.

136
00:09:30,630 --> 00:09:36,180
But for now, we're just using a name email and we set it equal to two.

137
00:09:36,510 --> 00:09:39,840
And the name is going to be in the H, the amount where we're sending.

138
00:09:40,260 --> 00:09:41,370
Hopefully, this is clear.

139
00:09:41,550 --> 00:09:44,580
So what do we want to do right now is export dysfunction.

140
00:09:45,030 --> 00:09:50,940
We want to go here with module exports is equal to send verification email.

141
00:09:51,000 --> 00:09:57,240
That's my function and I have to do a few steps because if you remember in the utos, I do have the

142
00:09:57,390 --> 00:10:00,360
next chance and I already have some imports in the register.

143
00:10:00,750 --> 00:10:09,540
So kind of makes sense to me if I add both the send reset password as well as send verification email

144
00:10:10,020 --> 00:10:16,260
in here as well, because that way I can use it with the rest of the stuff in the other files.

145
00:10:16,740 --> 00:10:22,920
So instead of sending email Liquidnet manually in this case, I'm going to go for comms and can remember

146
00:10:22,920 --> 00:10:27,990
the names and verification email is equal to we require it.

147
00:10:29,060 --> 00:10:30,800
I look for my files.

148
00:10:30,820 --> 00:10:34,580
So send us email and then we want out of here.

149
00:10:34,970 --> 00:10:36,170
Send verification email.

150
00:10:36,700 --> 00:10:40,190
Run where we have the off controller.

151
00:10:40,700 --> 00:10:47,630
More specifically, where we have right now the create token user and all that since that is coming

152
00:10:47,630 --> 00:10:49,340
from the utos, here's what we can do.

153
00:10:49,910 --> 00:10:52,100
I can go with send verification email.

154
00:10:52,400 --> 00:10:57,200
I can remove, send email for now and I'll start setting up that functionality.

