Email Verification In Node JS Part-A : User Verification Model Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you might have been in this situation before you visit a website or open an application which requires you to sign up to have access you don't want to share your personal email address so you enter a random one but after submitting it tells you that you need to check your email for a confirmation link before you can continue now because you entered a random email you're unable to proceed this provides an extra layer of security for the login system now let's see how we can implement that in a login system we will handle the backend staff in this episode and the front end in the next we will build on a node.js and mongodb login backend that we built some time ago i'll link it up here and also in the description below if this sounds interesting let's jump right into it [Music] the first thing we need to do is to open our command line and navigate to the directory of the project [Music] now we open the project in the code editor now inside the code editor we see all the codes that you wrote in the first part so inside the api directory we have the route for application that is the sign up and the sign-in inside the config here we have the details about our database and in the modules directory we have details about our user collection that is a collection of data about our users and inside the server.js we have our server which is running on ports 3000. now because to be working with the react front and later on you want to change the port to port 5000 so that there will not be any conflict now the first thing we are going to do is to adjust the user model so the user has name email password and database properties currently when the user signs up we store all these details in our database but to be able to differentiate whether asia is genuine or not we want to add a verified property to it this would be a boolean value which will have an initial value of force [Music] now also when we are in the process of the verification we want to generate some unique id and send it to the user's email which the user will use to verify the identity so between the process we want to store this details somewhere so we create another model and we'll call it user verification so inside the models directory we create another file [Music] now we copy the content of user.js [Music] now for the properties we'll have a user id which will be a string this will refer to the automatically generated id of our user record the next one will be the unit string now this would be a random string that will generate for a particular user who is now about to verify the account the next property will be the time that the account was created and that would be a date you also want to give it an expiry [Music] and that'll be it for either verification model now inside user.js in the api directory we want to import our user verification model we will do that under the user model [Music] now at this point you want to install some packages the first package you would like to install is nodemiller that will enable us to send the emails in our application also we want to install uuid which we will use to generate the random strings [Music] once you are done we import them into our api file [Music] now for the uid we'll do a little bit more [Music] now what is happening here is that the uuid has a sub model which is called version 4 and that is what we need in our application so while importing it you want to refer to it by uuid v4 now for the node mailer setup we make use of login credentials and we'll store these credentials in the dot emv file so to be able to access these credentials you need to bring in the dot emv config so let's do that we've already installed the tmv package [Music] now let's visit the tmv file and create our credentials the first thing we need is the email [Music] and the next thing is the password but for this value i will not show it to you now for the credentials that you provided you have to ensure that it corresponds to a valid gmail account and also in the settings of the gmail account you have to ensure that you've enabled assets by less secure applications and also you're not using two-step verification you also have to ensure that you've enabled access via the gmail captcha i'll link a video up here which goes into details about that now the next thing we need to do is to create a nodemailer transporter [Music] [Music] the transporter will have a service of gmail it will also have an earth property which will take the values that we put in our dot emv file [Music] now at this point we want to test if everything is fine with our transporter remember it is the one carrying the message from the source to the destination [Music] at this point we can go ahead to save and try it out so on the command line we run the project using nodemon server.js [Music] now we see that our server is running and also the transporter is ready for our messages so we can proceed will make our first change in the sign up block after we are satisfied with the details of the user we want to set a value for verified so at the part where we create a new user we want to add a verified property and we want to set the value to false now after the user has been saved successfully that is where we return a success message we'll cut this part off and this is where we'll send our verification email so we'll call the function here send verification email and as argument will pass the results and also the response this is where we have the response objects [Music] and that's all for this section we proceed in the next one please leave a like and subscribe for more to the point good
Info
Channel: ToThePointCode
Views: 32,850
Rating: undefined out of 5
Keywords: node js, node js developer, web app hosting, nosql database, cloud database, mongodb, mongodb compass, data warehouse is, google sign in, google account sign in, google login, mariadb, app hosting, install mongodb, mongodb pricing, aws mongodb, google account sign up, google account login, google sign up, redis, datastream, nosql, mongodb cloud, cheap cpanel hosting, top hosting providers, cheap wordpress hosting, ms in computer science, frontend mentor, js node
Id: v6Ul3o8D-js
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Wed Aug 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.