Golang HTTP User Authentication Yabi Series 13 | Golang Web Development | WebAssembly Auth System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys welcome back to the channel this is the true series number 33 here in melkin's code okay we are still in this yabby series number 13 now guys and uh this one we will continue on with our login system right now we need to uh enhance our login system first and then after that we will log the user token as a to become a persistent user token guys so this is what we are about to do in this tutorial now because once we restarted our web server or any kind like uh or even our web server itself will will be restarted guys then our program was capable of uh these what they call these login user's authentication this yabi here will be able to restore back our uh the users i mean the user's authentication guys like the user currently log log on but all those valid um users authentication and i guess those valid tokens that we can able to restore it the login system itself guys is a quite uh huge topic itself because this one it serves as a more secure security part of our login system guys so this is a very important part of our login system as well in the entire yabi series i mean the yabi series is uh it's all is uh i mean this is very valuable package that we need to uh more secure and we need to secure it properly guys otherwise we have some technical uh problem there there's some bugs in or can bypass the thing but the good thing is in our last discussion we able to prevent uh any pages that we want to we want this to be protected i mean we need these um pages that cannot be accessed without the user's authentication without the proper or valid users identification guys so that one we have achieved already in our previous discussion so if you miss that you can always take back on that video guys okay so also in our github there so we can publish this uh new latest source code for this yabi series guys okay so no worries about that and then for those people who want to uh honor here in harlequin school just leave a comment down below guys don't be shy okay just kidding anyway just call comment down below guys so um anything that you want to share or something then you just leave a comment down below okay um just to support this channel also guys okay thank you so much for supporting my channel here american school we learn together here guys so no worries we will share uh whatever we have uh uh achieve here in manikins codes okay so we have a lot of topics here so a lot of series uh going on uh not only this yabby but in the future thing there so once you once we log into our dashboard there there's a lot of uh things that we can do inside that of course inside the user's account guys so we can uh um maybe in our probably in our future discussion will be uh the what they call this uh uh real-time notification guys uh to the dashboard there something like there's a notification plus one or something like new notification will be elected there the user something like that yeah so we can probably do that and then file upload the user can able to upload a user's profile there something like the image these are all the things that we can do a lot of things there guys so stay tuned and now here in harlequin's code okay so let's dive into this tutorial guys okay guys welcome back to the channel okay uh this is the thing guys we need to continue about this uh joby series here uh at the moment guys we need to tidy up a bit our application here this one we want to tidy up this thing guys because we already fixed it into our uh right that byte here guys so to respond as a json format there back to the users in our web assembly so uh this thing is not a nice case because this one temporarily we we put it here at the moment because we want to test it uh straight away we need to test first so right now we need to tidy up a bit guys so that it will uh looks more professional guys okay okay so uh we will tidy up this one and then we will base it one because once we upload it to our production server there we just want to switch it with just a few configuration guys so we would like to do some configuration for our yabi here so we need to set at least one thing in our main here guys in our main uh that go uh from the root go guys okay the root so we know we will add uh maybe below here so we can just add on guys but before that we need to add some configuration guys whether it is a production server or not so so we are in the local development there so easy for us once we publish this into our github okay guys so uh we will continue on so by doing this we will open these settings that go into our from our yabby package here guys remember guys that this yeah be here this yabby package we will publish this into our github there so easy for us or you guys there to use this uh package okay so we will publish this on github then you can just go get this one and then you can use it in your application itself so it's really um a lot of things we have to do guys in this yavi series itself because this one after our final final product or final software that we will publish and share it with you guys out there so that we can reuse this jrp series if you want to use these guys okay so we will we will start enhancing our configurations here uh like that uh localhost or a production site so right now uh we will enhance this one guys so we will create a new uh simple initialization or the configuration here first guys but otherwise uh we cannot uh proceed with our clean uh tidy up so okay we will tidy up now guys so here we will just have to uh it will create us what they call this struck guys okay hold on for a while guys we will create this initiabi uh struck so this is our main configurations guys that we need to load so in the future we will add on a few things guys right now we need to have this base url first uh whether is it a localhost or not then uh example we just put some example here guys uh maybe our 127.0.0.1 okay then there is a port there for our localhost or you can uh https here in our production guys like for example maharlikanzcode.com our our favorite domain uh of course with the uh trailing slash guys so so that we will avoid always putting uh at the back at the last one and the last part we avoid always putting when we concatenate this base url with our uh with our uh routers guys okay this one is initializers initialize the common you know just the common configurations guys so i just put all this information guys so that we will properly note everything guys okay uh package yes okay uh and then we will add on this uh muha i'm you guys we just used this sync mutex uh this one is very useful guys when uh because we are uh initializing this uh this uh yabi struck here guys so this sync mutex will properly handle the golang itself will properly handle um any uh override something like this like these settings here it will properly do some uh locking there or preventing some like like uh in a split second or something like uh updating together with the same user guys but this one is uh we just want to prevent this to happen like any type of memory crashing guys for example because this one is uh we already initialized and then when the user tried to override it so this one is just uh just to prevent guys most especially when we are doing some configurations guys like uh destruct this kind of struck we will add this kind of uh internal sync mute next guys so this one just to prevent uh this one is to ensure uh like atomic uh rights guys this this what the uh the documentation always say is atomic rights okay so when we write into the memory it will just prevent something else okay this means okay so we just want to add this then this sync mutex is also added now this automatically added okay so right now we need to add another variable guys this is our public variable again so we just add this pointer guys for this truck this one is yeah we not fb okay uh the pointer okay for innate uhb configuration okay configuration so we have this initialization it is easy for us to call this uh initial big so no need for us to always call this truck the full name guys so we just want to create a shortcut there uh funk uh yavi config so right now we are doing this um initial b guy so this one later when you use this uh yabi siriab package guys easy for you to set those configurations guys okay just hang on for a while check all the required configurations and figures are in place [Music] or not oh okay just leave it if length okay we just want to check again uh trim space always do this guys okay uh trim space although it's keep repeating guys it's very useful okay just take your copy guys okay so now um we will set the initial value guys okay but because we all know um when you're working with the localhost or your internal thing this one later no worries yes later you can override this i will show you later this one is just our internal uh initialization guys with the default default port number and then when um don't forget this trailing slash guys okay then you can return uh this uh initial v here okay so we will provide with this re base your okay it's good enough again our favorite notes initialize always do the notes guys necessary yeah be configuration configuration and its default value okay values okay uh now we will try to do the initialization guys with the default value here so we do the func init here and then we will set something like a set initial uh default uh this one is is this one is for the set initial default uh yeah we can config need config and then we will store this uh init yabi i need diabetes so we just want to use this okay uh we just put blank guys because we already set the default value at the moment because we already we so far we have base url configurations guys so we just uh in the future we can add multiple config configurations here so at the moment we still have one configurable variable guys okay for you later you can just change this i will show you later guys okay now we already set the moment your go program run and execute this as well guys okay then it will load this base url if you never put this base url in your main.go in your root main.go then i will load uh this initial value guys otherwise our all our urls here all these things will be blank guys okay please understand guys okay this one is very important you should load this you must load this okay otherwise how you can run the your server http server okay whether it is a local host or something in your production so right now we just initialize it with the empty struct because we know we have the some conditions here then it will load automatically uh i will load automatically the yabi our yabi package will load automatically this default address guys okay with the default default port number right now we need to do this initial another function guys uh okay we will set this okay i'll create this function first set yeah v config this one is your customize now guys okay um you need yeah this is how you're going to do with your configuration guys huh okay this pattern guys you will always do this pattern okay these configurations here later this initialization and then the user's customization this part what we are doing now okay um this one this code is really useful for you uh whenever or whatever you're doing you are you are accepting users configurations guys okay this is a very important you always have this uh kind of a code okay okay so we will do the mu dot log okay and then we will unlock first this one is the user's customization guys otherwise if you don't want this then you can no need for you to log guys then you can remove this but right now we we are accepting users uh own configurations guys later part we will use this so that's why we need to lock first because we we already initialized during this time during this stage level or whatever the name this one already said then it's an initialization of this value then if the user called this at the here in the main go whatever the main route that go is residing there of course it's in the main goal here it's in the root go or root package okay so then we will set this uh customize value guys okay we will defer first be that mu dot then we will unlock guys okay now we enable to we already unlock this then we can do the atomic rights for that memory pointer guys that pointer there we will do that you know so we can uh we can now uh safely write the new variable i mean the configurations guys oh check all the required configurations are in place okay just again on a flan okay if land uh strings that dream space again here okay hold on guys be that bass uh okay we just basically we just see sorry guys i just actually save money okay so if land base okay then we will do this reconfigure now reconfigure okay reconfigure the yabi configurations okay uh b we will use that b to overwrite the initial value guys and then of course the user's variable as well okay we return with b okay done now we will do this again sets the custom this one custom requirements custom configurations guys config values from the users from the from the user okay it's enough okay now we will initialize this one guys okay we will use this here so probably we can have these things in uh hold on guys so here is the best right here okay so initialize the yabi oat api here okay so yabi base url and local variable here guys so just put some initial values guys uh this is your own okay this is your own customized thing guys we will customize these yabi configurations guys your own base url okay and this is how we're going this one we are using on top guys this one we already said in our previous discussion very old discussion guys as you can see we already set here and then of course this is broad server mode if it is false then this is served as a local development guide otherwise if it if you set through then it is a production server okay you you are using your domain name okay then we will continue on so we already catch this ip here what we're going to do now is uh just add the trailing slash there okay this is the default to div the deep locals okay so if uh i think it's it's prone okay we already set there on top so easier for us guys yabby so we will initialize this uh config that site base url okay base url so we don't have for production guys i guess we don't have uh just go on for that side first hold on guys i need to check this one okay we have this prod here and then the development okay or whether you use this or not so i think we use this and then this is for the production side okay so if it is true then we will use this one guys this one okay this is the production site there you know so we use the domain name otherwise it will use the default here which is the http whatever here because this one is only ip address yes without the http okay so so we will add on this http here and then the trading slash so right now we need to set this um yabi that now we will use this one guys yeah be config this is your customized one and then we will use this uh okay initial v so this is the struct then we will supply the base url you will supply the what you call this get hold on base uh url with the yabi uh this one guys base you are you base your and just take a look on top guys it will started hold on guys oh it's here it's already there so now it is uh we already set our customized configurations guys one more thing we need to do is we will go to this this one no longer in use this one we will change accordingly guys we will search this kind of thing http something thing is in the old yeah yeah here okay now we will change this one guys okay hold on hold on guys uh we will do the correct symbol then we will uh check with the ob dot yb that base url guy so now we can easily use this i just want to copy this one guys okay so you'll find all those things so we found three here so this one we also want to change this okay but this one no nothing okay so we already changed this one as well okay oh another one one more so now it's very clean guys and very nice i hope you okay but this one is a more recommended way okay now is a very clean guys we have these configurations here from our main uh that uh main goal here in a root main.go so we have now uh successfully set this okay so it's time to test guys this thing it's really working so this one is the login page i guess no register this one is the login okay this one is login so we will see if this one really redirects to the dashboard there guys or not okay once we log in successfully otherwise it will not succeed guys to login okay so we will try this at the moment this one don't have the we don't have changes to the web assembly there okay so you know you hold that go so we'll try to run and then we will try to uh we have still our one user here so okay so we will uh okay guys so uh we we will do this uh this one i think you need to refresh first guys this is our previous discussion there so right now we we don't have this yet so now is a moment of truth guys we need to login we will test first guys okay we will proceed with the correct one it it should redirect to the dashboard immediately guys okay with our new configurations okay it's working properly guys and go back to the login again let's see okay it's good okay guys uh now our yabi configurations is totally working guys it able to it is able to redirect us with this new one okay uh we can also test this by fmt print line but uh we want to save our time guys again we can test along guys okay test also this one is totally working now guys okay even if you want to change here this part with your server here you can always do that again okay very nice now very clean configurations here we able to successfully set this base url here so in the future guys if we have multiple configurations we can add add-on additional here guys just put a comma here but right now we will only have base url here one configuration okay okay okay guys and then we need to enhance this one also guys uh what i mean these are lost login because we need to adjust this when the user successfully log in guys at the moment we don't have this uh what you call we don't have this um function yet to update that lost login guys so uh what we can do is uh we need to tidy up first guys uh fun we will create a new login guys under this user.go okay uh we will create this and then db con same thing with this one and then we will just copy this one guys okay to speed up our thing and then it's just a simple function guys uh just to update uh this thing so we will update here same thing with the previous one guys so dv con uh db cone dot prepare need to do the update statement guys update and then plus yeah b user here of constant variable and then uh i need to set the last uh login sorry login thing okay the moment the user adjusts guys so okay and i'm sorry and his active is only true okay so he will uh capture that okay uh i ordered that equal to neil then we just work with our itr logic okay um sorry error from [Music] last login okay you just want to easily catch up the thing guys not the virus the specific specific users last log in with the current timestamp okay so just do the simple update guys pass all the parameters parameter values here upd dot exec okay and then time that now then we just use this one guys the current timestamp then the username there and then it's true and after this we don't forget to close guys defer update close okay so we have this and then we would like to insert this in during the successful login guys okay then probably okay guys uh we will add this here update the last login guest so we will in include this during the successful login guys so okay the password match then uh successfully we log in here so okay so update the user's last login to a current timestamp okay then we will use this last login now db con okay and then we will just use this m user here done guys uh i'm user dot uh username okay so we have this a plain username without the encryption guys so we will do this yeah correct okay so we will uh use this uh update guys and we will now we are about to to test this okay uh right now the last login is uh this one guys so we will have some demo dates here so since the beginning we never update guys okay we just want to play around this one should change to the current timestamp which is the second of february guys okay so we will just run this again and let's see it will update upon successful successful authentication guys now our server is running the date is 16 of january okay oops sorry just want to replace first okay so we will uh give you the correct password guys okay so now successfully login this one should change upon clicking the browse again guys so i think it's not it's not changing okay guys we need to check for okay hold on last login so this one is true hold on guys you need to check first uh one more thing we need to double check if any errors there okay with this error lost login so probably there is an error there guys okay set last log in okay and then sometimes life is [Music] messy guys okay and is active okay so this one should be okay now okay uh we'll run again guys so that's why never change we don't have the where statement okay so we will just refresh this okay uh run again it should change guys to current date timestamp okay now change change to the current timestamp guys so so far it's the second of february okay so now we are able to slowly we tidy up our thing guys okay so [Music] this time or the moment every time the user login successfully we will update that last login guys this field here so okay we have done that so probably in our next discussion guys we will do the token here we need to make it persistent guys uh the time is not permitted for us this time okay so we will do this yabi user token guys uh we will insert this token upon user registration fund the successful users uh login guys authentication okay the validation everything once it log in then we will keep also the token there guys of course with the bytes something guys so this structure here is a token key this is just an index one this is our username so we can accept multiple token key this token key is our encrypted username guys then there is a data here which is the var binary so we will store a byte data here and then of course this token source uh probably looks like uh is a oat or these are all the indicator you guys so our own indicator okay so because we are accepting multiple same token key which is the username but we of course with different token data so either a password reset or a users authentication the old or the new user's activation so we will store all in the same table guys okay of course with the expire on here in the table okay so we will manage this accordingly so we will make our token persistent guys this is very important when uh when like this when we stop this server then all the memory there all the golang's map there everything will be gone guys so we want to prevent that to happen so the moment when we run again we will restore all the active uh active tokens only guys okay okay so that one is should be our next uh target guys okay okay guys uh thank you so much for watching here in markets code and i hope you enjoy our attitude series here guys in maharakan's code and we learned together here in marlingan's code thank you so much for watching and this tutorial series and i hope it's valuable for you guys out there especially those students or just or those people or just learn golang guys and then uh we can uh work together here we can learn together here in malagan's code just leave a comment down below guys uh to shout out you in our next section to honor you here in malikan's code by reading your comments and flashing out in our screen into this shout out section for our uh and every end of our video guys okay because our priority is the the curious series here okay but we would like i would like to honor you here in malikin's code those are viewers and then those students okay thank you so much guys uh please consider subscribing to my channel okay so that uh i will be honored also okay uh we have some few comments here guys we would like to read and also in our previous uh videos tutorial videos here so maybe i will i will honor those people also uh those who commented in our in our previous uh very old videos guys that we have here okay so the first uh uh user that we would like to honor here is uh in our previous discussion she commented this uh his name is uh maybe honey i don't know uh yumi pao pao okay uh ayumi pow pow thank you so much for commenting out on my video okay and my tutorial video guys and then another one is uh for our previous discussion guys this one very old in our how to publish golang package in our section here in our last discussion his name is annoying ross okay just annoying rush thank you so much for commenting a nice comment here and thank you for watching and also [Music] bandari official yeah okay so thank you so much bandari for your nice comment here in marlinkinskog.okay and then another guy is nitish dubi okay thank you so much nitish for commenting out on my old video okay then those people i honor here in maharikan's code thank you so much guys uh for watching here in martin's code and i hope you enjoy a lot here and uh thank you so much for watching and then uh please consider subscribing guys to my channel and we can learn together here in marlikin's code for those people who don't subscribe yet okay uh thank you so much for watching may god bless us all thank you and bye bye keep safe everyone
Info
Channel: Maharlikans Code
Views: 168
Rating: undefined out of 5
Keywords: Life As Software Developer, go, golang web development series 33, golang web development course, web development with go, golang tutorial, learn to create web applications using golang, building scalable web apps in golang, golang good for web development, golang http user authentication, golang http authentication, golang authentication microservice, golang session authentication, golang webassembly, golang mysql, golang mysql tutorial, golang sql, golang login authentication
Id: t_NJhH2t1Zg
Channel Id: undefined
Length: 40min 20sec (2420 seconds)
Published: Tue Feb 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.