Email Verification In Node Js Part-C : Email Verification Link Expiry

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
yeah welcome to the next section link to the preview section will be up here and also in the description below now at this point we want to handle the route for the actual link that the user will be clicking on in the email and that will be a get request [Music] remember the end point to before slash verify this is preceded with the user that is because inside the server.js file we told the application to look for forex slash user before making use of the api that we have therefore each route in the user.js file will be preceded with forest lash user before it is actually used [Music] also while sending the link to the user we attach some details which is the id and the unique string so while handling the routes you want to fetch those values [Music] now at this point you're going to do a few things the first thing you're going to do is to check if the verification record actually exists otherwise we'll return an error message so we search through the user verifications using the user id let's return a promise [Music] now for all the outputs that we'll be doing in this route instead of returning a json object we want to do something more we want to return the user to a page where the error will be displayed either a success message or an error message so i have an html file that i'll be using so let's copy the html file into our working directory so we create a views directory and copy the file into it now inside the file depending on the parameters that we pass in the url it will display a particular message either a success message or an error message and it will also customize the message on the screen based on the message that we pass in the link so before we proceed we want to create a route for the file and it will be a get route as well now over here we want to return the static html file and we are going to make use of the path object so let's import it [Music] we make use of response dot send file this will refer to the current directory and the second parameter will be the path to the actual file since we are inside the api directory we need to go back a directory before we can access the views directory and then to the html file now once we are done we go back to our verify email route so inside the catch block here we set a [Applause] message [Music] once you have the message we redirect to the route that we have here and attach the message to it we are making use of the redirect because this is the only way we can call the route here and also pass the parameters that we need to pass the verify idea refers to the end point here first we specify that is an arrow and then we add a message to it [Music] now we are fine here and we can go into the den block before we go let's copy this this will be the format for all the outputs now once you get a result the result will be an array so you want to check if the arrow is not empty else if the result is empty we return an error message [Music] so paste what you copied from here [Music] so what this means is that once you don't find the record in the user verification collection it means that maybe the user has already verified the account or the user hasn't signed up at all that's why we are telling the user to either sign up or login for the redirect everything will stay the same so once we are sure that there is a record exists the next thing we need to do is to check if the record has expired or not remember we said the record will expire in 6 hours so now we check if the record has not expired so from the results we distracted the expert remember this is an arrow so we target the first index so to confirm that it does not expired we compare the value of sparsat to the current time [Music] if the value of expires at is less than the current time it means that the record is no longer valid [Music] so once the record has expired we'll go ahead to delete it from the user [Music] verification and we'll delete this based on the user id [Music] let's return a promise as well so we handle it [Music] so we paste the message here too [Music] and that's all for this section we proceed in the next one please leave a like and subscribe for more to the points good
Info
Channel: ToThePointCode
Views: 8,123
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: FhqWF5veVGo
Channel Id: undefined
Length: 9min 32sec (572 seconds)
Published: Tue Aug 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.