Advanced Godot | Creating a Login Page With Firebase

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is mitch with findpoint cgi and today we're going to talk about creating a login system with firebase so we're going to install the plugin we're going to create the buttons and create the login screen we're going to go ahead and set up firebase and then finally we're going gonna hook godot up to firebase so you can fetch out data and store data about the user so we will hopefully be talking about the fire store as well and storing user information inside of firestore so that's what i have in store for you guys today so let's go ahead and get started all right so the first thing we're going to do is we're going to talk about the plug-in here and this is the godot nuts godot firebase plug-in this plug-in allows you to interact with the firebase sdk with gd script without needing to use an android plug-in so previously the plug-in that we used for firebase was specific to android because it had a lot of extra android features push notifications sending out um admobs and things like that this on the other hand primarily just does authentication and database connection so we'll be looking at both of these just to make sure that we are covering the entire plugin and things like that so the first thing we're going to do is we're going to download the code so let's click on the green code button and click download zip and we will go ahead and save that now i know that you can add this from the godot asset library but i did notice that it didn't work with the current version of godot at least at the time of this video recording you can try using the asset library version which i can bring up right here asset library and type in firebase and you'll see right here is the godot firebase plug-in the problem again with this plug-in is it didn't work with the current version of kado at the time which in this case is 3.23 i recorded i know 3.3 is coming out uh sometime next week so that should be exciting but for right now we're just going to go ahead and download the godot plugin so now that we have it downloaded we're going to come over here we're going to right click extract we're going to extract it and then we're going to go ahead and open it add-ons and you'll see that we have our add-ons and all of our information here now we're going to need this entire to uh go ahead and do our firebase integration so what we're going to do is we'll open up godot engine we will right click open in file manager and we will right click add in a folder and call it add-ons we will go inside of that folder and paste our plugin in so now godot should recognize so if we go ahead and go to our project settings we can come over here to plugins and you'll see that it notices that we have these add-ons so we're going to go ahead and click enable on both of these so the first one is the go firebase sdk add-on so it allows you to interact with firebase and the second one allows you to do https connections with firebase you need both of them to be able to have a secure connection to firebase so we're going to hit close and now we're going to move over to firebase all right so i'm sitting here looking at firebase the first thing we need to do is add our projects let's go ahead and add our project and we will call this firebase non-android test project that's a mouthful but it'll work and i will allow for google analytics just because i might as well i'm going to go ahead and use the default account we're going to go ahead and create that okay so now that our project is created what we're going to do is we're going to click continue and we're going to be logged right into our application now we need to create a web app so we'll click web and we're going to pick a name which in this case i'm going to go with firebase non-android test project that is a mouthful go ahead and click register app we're going to want to take note of these items here so if we go back to our so i want to take note of our add-on here if you if you go back to the domain you'll notice that there is an override config file so if we copy this we're going to open up our godot project we're going to right click open in file manager let's go ahead and paste right here override config and we're going to open up visual studio code so i'll type in cmd and then code dot and that will open it up into our directory and go ahead and close that if we open up our override.config you'll notice that we have an api key an auth domain a database url and a bunch of other data here now this is extremely important for your project because you need to put all of your godot all of your firebase information into here so if i go ahead and minimize godot and i pull a visual studio code over here let me just drag this over a little bit all right and then i take this firebase api key and i pasted an api key off domain i do the same thing i copy it i paste it in here database url there isn't one as you can see project id i copy that and i paste it into project id storage bucket i do the same copy and i paste and then messenger or messaging sender id let's copy that paste that app id which is our applications id go ahead and paste that in here and measurement id so i copy that and i paste that now what are all of these things this is your api key so this is your actual unique key to get to firebase's api your authentication domain is the domain that you're authenticating against project id is a specific project that you're authenticating against storage bucket is your actual uh storage i guess location if you want to call it that messaging send id is your specific sending id for your application an app id is your actual application id and measurement id is your analytics id simple enough right so if we go continue to console you'll see here is our firebase console so the first thing we need to do is we need to turn on authentication so first things first authentication and then let's get started with authentication it's going to go ahead and create our authentication system and we're going to go email and password let's go ahead and click enable it let's go ahead and click on the little edit configuration button and then click enable and then click save all right so we just enabled authentication for our application using email and password now the scope of this tutorial is not going to cover phone play games game center facebook twitter github yahoo microsoft and apple the plugin doesn't really specify anything about those it does specify stuff about google so we can take a look at that but when it comes to the rest of these it really doesn't specify much other than anonymous and we'll go ahead and cover that as well so we'll enable that one as well so if you click on that and enable and save i will show you how that one works as well so now let's go back to godot so if we open up godot the first thing that we're going to do is we're going to create a user interface so you'll see user interface control has popped up and then we're going to right click here add in a child node we're going to add in a line edit awesome so we'll drag this out put this right here we're going to duplicate that with ctrl d and drag this over we're going to call this username and password so we're going to go ahead and create two labels right above this put it right here we'll call the first one email and the second one i'm gonna call a second one password and now we need one button to log in so let's right click add in a child note and call it button all right we'll call this login we're gonna rename this to log in as well it's always important to rename all of your things as you're working because it makes things easier to organize later alright so now that we have that we're going to right click our control node here we're going to attach a script we're going to call it logincontroller alright so the first thing we need to do is we need to connect our button so let's click on our button go to node on button up right click and connect that to our control node here so we have this little function on login button up so let's go ahead and say var email is equal to dollar sign username dot text and var password is equal to dollar sign password dot text and now we need to go ahead and fetch our login or go ahead and send a login so let's do firebase dot off dot log in underscore with underscore email underscore and underscore password we're going to pass in two arguments and that's going to be email comma and password all right so what is this going to do when we click this button it's going to get whatever we put into our our username and it's going to get whatever we put in our password and it's going to send that out to authenticate with the google servers so let's go ahead and try running that and if we hit play it's going to say hey no main scene so yep we haven't created a scene right so we need to actually save first so let's go ahead and save and call it firebase login dot or tscn i always get that wrong hit play hit select and let's go ahead and select that so that's going to allow me to to see all of my scenes and let me play with them so let me type in my email let's say kh at maildrop.cc which if anyone doesn't know what mail drop is it's basically a place where you can make fake email addresses so that you can do testing like this or or if you want to sign up for something but don't want to give them your actual email address mail drop is great for that so if we just say password one two three four and log in you'll notice that nothing happens also you'll notice that our configuration seems to be a little on the broken side here configuration key api not found right so we need to figure out why that's the case but you also notice that this isn't working either so we need to figure out why this isn't working and why this isn't working so let's take a step back and look at why the configuration key and stuff is not working so let's right click open in file manager and actually let's go ahead and open up our thing here and that's because we forgot to save or at least i forgot to save you can see if i scroll this down a little bit see that there's a little tiny dot here that says i didn't save so let me go ahead and save that and let's try again and see what it does and then pass word one two three four log in you notice that we're not getting anything back there's nothing going on now the reason why that is is because firebase sends a bunch of different signals back for you to uh pay attention to so that way you can get information about what your firebase is doing so in this case let's add a firebase dot off dot connect and let's connect their login underscore succeeded comma itself because we want to hook it to ourself and we want to hook it to our underscore on underscore firebase off underscore login underscore succeeded all right let me grab this here let me go create a function down here all right and what that'll do is that'll say hey if a login is successful we want it to do something so let's go ahead and print success all right and now we also need to see if it failed right because we don't want it to you know if it fails we don't want it to uh so now we need to see if it failed so what i'm going to do is i'm going to control c on this and paste it so that i have two of them and i'm going to connect login failed here to on login fail and we'll grab this we'll scroll down bring this over on login failed and what we're going to do is we're going to now what we're going to do is we're going to pass in some arguments here error underscore code comma message now i know that you're asking how do i know some of these things and that's because in their wiki they have some really beautiful written documents here now some of them are not written 100 proper so you're going to have to do some sussing on your own just to let you know but it does give you some really interesting stuff so for instance if you're trying to log in with email and password it's saying hey that's what you need to call login with email and password right or if you can see that it has signals here login failed has a code message right so it has code which is an object and message which is a string so if you swing back you can see i'm saying error code and message right here that's from right here login failed code message so that's just something to keep in mind when you're doing your project is you really want to look at their documentation to to see what you're trying to do here so you can say error code message let's go print hey our error code so our error code is we're going to cast it as a string because i don't know if it's going to come back as a string or if it's not going to come back as a string so we're going to want to print it as a string and then we're going to do the same thing with message and again we don't know if it's going to come back as a string so let's go ahead and print it as a string right so now we can refresh our page go ahead and type in our stuff log in and you'll notice that we got an error code here error core 400 email not found so where are we at in our process well we actually have it all set up properly right we have everything set up it's going against the database it's checking to see if that email exists the email doesn't exist so we need to to register the email and password with the firebase servers so we're going to right click on our control add in a child note add in another button here we're going to move it over here we're going to add a text called register all right and then we're going to call this register all right we're going to come over to node we're going to click on button up double click on it and we're going to hook it up to our control node and add that in so you'll see it automatically correct created our little function here on register button up so what that's going to do is it's going to send out to firebase and try to register us right so we want to go var email is equal to dollar sign username dot text and then bar password is equal to dollar sign password dot text and then we need to call out to firebase so let's go firebase dot off dot sign up sign up underscore with underscore email underscore and underscore password email comma password all right so now we're going to go ahead and save and we're going to attempt to register so let's refresh and let's go cage at mail drop dot cc password is word123 and we're going to click register now you'll notice that nothing happened we didn't get any return we didn't get any information saying that we did right but if we click login did anything happen well we're not sure right and that's because we may or may not already be logged in and we did not connect our callback here for our register so we need to come up here control c and control v it and then we need to hook up sign up underscore succeeded comma self and then on firebase off sign up success right succeeded so we'll just grab succeeded it's probably fast for me to type it but then we'll paste that in all right so now i'm gonna go ahead and grab this section here scroll down and go funk on sign up success and let's go ahead and check our document here we're getting off information so it looks like we're getting back some user data here with our sign up successful we're going to print out sign successful and we're going to take in if you look at the documents again it takes an off information of a dictionary right so we're going to say off info because we might as well just name it the same thing and we're going to print our auth info if we hit play oops forgot my dot we try to register we get a 400 error code right here that's because if we go back to our android test project and we go look at our users they already exist we successfully registered our person so that's exciting right it allows us to get a user id it allows us to say when they last signed in when they were created and what what they said logged in under so now to verify that this works let's put a break point here and let's refresh our page and let's go with ls at mail drop and then password one two three four register and you'll see that we get back some data here so we have our auth info which is a dictionary it says hey kind id token their email their refresh token their expire and their local id now as a side note i'm going to save this information because this information is very important for future stuff in our project right we could use their email for something in the project right or we could use their id token for something in the project so what we'll do is we'll scroll up here and go var user info is equal to null and then what we're going to do is we're going to pass off underscore info and we'll pass that in so that way we get their login information so that way we have it just kind of held in memory over here now also while we're at it let's take a look at our login successful callback so we can see here login success right so if we come back to our documentation here and we look at it you can see that their login successful gives us back the exact same auth info so if we come over here we can pass in the same thing off info and we can just copy and paste this over here so that way whenever the user logs in or if the user registers we get their information so that way later on in the game we can actually use it for our own purposes so now let's verify that we can even log in so let's go with kh at mail drop and password one two three four and let's put a break point here and let's log in all right we've got a success we got back all of their identity token information their local id their email their display name if they have one an id token a regi if they're registered what their refresh token is and when their stuff expires so that's really exciting now we can just hit play and we're good to go we're logged in so now that we have all of this what if a user forgets their password right what if they're like oh is it one two three four or one seven two six or something like that right well what we can do is we can add in a reset password button so if we go button and we added a new button and let's just drag it underneath here and say forgot password up here and then let's go ahead and rename this to forgot all right now if we go up to our node here and we click button up and connect it to our control node you'll notice that we have another little function here that godot has already built for us and we can say var email is equal to dollar sign username dot text and then we can say firebase dot off dot send underscore password underscore reset underscore email and we're going to pass in that email so now if we're playing and i say kh at mail drop dot cc and i go ah you know i can't i can't remember my password was so let me click forgot password what happened right we didn't get any feedback or anything like that and there isn't a callback for that so we don't we don't know right but if we go to mail drop and up here we type in kh which is the email that i was using for this you'll notice that we get a don't reply so if we go ahead and click on this you'll see that it says hello follow this link to reset your project id password for your kh mail drop account and you'll see here's a link so if i actually copy this link and i paste it in my web browser you'll see it wants me to reset my password so if i go with password 4321 instead see and i save it says hey congratulations you've now signed in your or you've now changed your password so if we come over here and we go password 4321 we log in you'll see now if we look at our firebase all right our godot project success we've successfully logged in with our new password so that's how you can go about resetting a password inside of the firebase system so what if we want a little bit more security right first of all we don't want them to be able to see their password information here so let's close this and let's go ahead and click on the password uh input box here and go to the inspector and you'll notice that if i stop the project and i re-click on this uh you'll notice that they have a little secret button here so we'll go ahead and turn that on so now when we play and i start typing in here you'll see that it just shows stars instead so that's a one really fast way to increase security in your project now the second big thing that we can do is we don't want people just to be able to set up with a fake email address like we just did right well we don't want that but we want them to at least have access to that email so that way we can send them like promotional things right we want them to be able to get that inform you know so that way we know that it's a legitimate email that they're not just putting in i don't know some random guy's email right well what we can do is we can actually send a authentication email to them saying hey you uh need to prove that you are who you say you are right so what we can do is we can say hey as soon as the register button is up and this all happens and the signup is successful and we have the authentication information what we can do is we can send a authentication email so we can say firebase dot auth dot send underscore account underscore verification underscore email and what that'll do is that'll send out an email to that person and say hey you need to prove who you are so for instance i try to register a new user so if i click play and i try to register a new user vic at mail drop dot cc password one two three four and i register oh it looks like we got an error here so let's see what happened oh you'll see that i got it in a in valid operands because i need to cast that as a string that's why it's mad at me let's cast that as a string and let's go ahead and reset this oh and i'm missing my closed brace here so let's refresh we'll try vic 2 instead and we'll register so now you'll see hey hold on a minute non-existent set account verification this is supposed to be send account verification email not set account verification email so let's try that one more time so pic3 at mail drop dot cc we'll put password one two three four register and now you'll see that first things first in our output we got a lot of information here right here which is they were successfully signed up here's their id token so that's good so we have their unique identification number here is their kind here's their local id their refresh token so we got all sorts of information from this person so that way we could use it later for our own purposes and if we go back to mail drop and we type in vic3 when some time will go by but we will get a verification email saying hey you need to verify all right so you can see that we got a notification here verify your email for project insert stuff right so we can click on that and you can see follow this link to verify your email so if we copy that and we go ahead and paste it you'll notice that now our email is verified so if we look i go ahead ahead and i refresh you can see we've got all these users and when they last logged in we can also look at you know their uids and things like that so now what if we want to change those messages that we send our customers well we can go to templates and we can actually look at them right here it says like verify your email for person right so you can actually change this and say hey from no reply reply to verify your email for whatever and then we can actually change our actual message here as well now if i remember correctly you do need to pay money to be able to change this so most of us are probably not going to change it but it is an option here so you can actually change all of these little things here which is exciting you can also set up your own built-in email server to handle all of that as well now i'm not going to cover that in this and i'm also not going to cover sms valve verification but these are some options that you have to authenticate your guys's emails so now that we got our login system working quite well what we can do now is we can so now we got our login system working let's see what else we can do with firebase with this plug-in now this plug-in is a very simple plug-in in the sense that really you can only do two major things well three major things but we're only gonna really cover two of the major things uh the first one being user management and authentication which we just went over and the next section which is the firestore section so if we go ahead and go to firebase here and we go to firestore database you can see here here's our cloud firestore so we're going to go ahead and create our database and we'll start it in test mode so everyone has access to it we're going to click next and we're going to chose us central because i'm out in the central location so let's go ahead and select that or whatever the default is for you guys should be fine all right so the first thing we're going to do is we're going to start a collection we're gonna call it user data and we'll add in a document and we will call it and we'll say we'll call it fine point cgi and we'll say field name which is fine point cgi and we're going to add in another field and call it score we're going to call that a number and we're going to say 25. so there's this guy fine point cgi that got 25 points and their score so first things first let's go ahead and get this data back and then we'll talk about adding some data and then maybe deleting some data and things like that maybe running a small query on this data so the first thing that we need to do is we need to add a button to go ahead and run that query so let's add a button all right we'll move it over here and we'll say get scores and we'll go ahead and connect this we'll just control c can copy that paste it in here all right and then we will connect our node button up to our control node here so double click on this control on get scores button up go ahead and click connect and that will connect this button to our script over here so the first thing we're going to do is we're going to need to type bar buyer store underscore collection and we're going to cast that as a firestore collection we're going to say that's equal to buyer base dot buyer store dot collection open and then we need to name it whatever this is so user data so quotes user data i'm going to go ahead and hit enter and then let's go ahead and fetch our fine point cgi data so firestore underscore collection dot get quote fine point cgi now we need to we need to wait because we're going to be getting a lot of data from the database so we need to actually wait for that to happen so we're going to say var document and we're going to cast that as a firestore document and we're going to say hey that's equal to yield buyer store underscore collection comma quote get document and what that's going to do is that's going to set this document data here with the get document functions return from that firestore collection i know it's kind of confusing and a little weird but trust me like that's it's not so bad it's just kind of confusing uh so we're gonna type print uh document so we're gonna go ahead and print that document so we can see it and i'll also throw a break point here so that we can um you know have it work here so if we go ahead and hit play and we click get scores you'll notice suddenly we have all sorts of stuff going on here first of all we get a document back so that's exciting so let's click on that and click on inspector you'll see doc name doc fields dictionary we got back our data and we got back our document information you'll also notice that we got back all this stuff well hold on a minute you know it says hey unauthenticated request issued and it says okay well we signed up you know go ahead we're good you know that's okay now the reason why this was okay is because in our authentication we set up the ability to have anonymous authentication if we didn't have a anonymous authentication it would have failed so let's go ahead and shut off anonymous authentication here and click save right so now we just disabled it so if we refresh this and we click on it you'll notice that hey hold on a minute you're not allowed to do that you need to either enable anonymous sign in or you need to authenticate before you do this so if we come back here and we type in vic2 at maildrop dot cc and we pass in her password we log in you'll see success we successfully logged in and i'll get rid of this break point because we don't need it anymore we are successfully logged in you can see a success here and then if we say get user score now we've got that user score again so it depends on how you set up your firebase but you either need to authenticate or you don't right but this is how you get basic data back from firebase so you can see here we got back our dictionary with our names and our scores so there's our name there's our score simple enough right we also have a document here which is right here right here and in that document we have more additional information created time update time things like that and we have our fields so you can actually see our field information as well so you get back a lot of data when you do these things so now that we've got data coming back what if we want to add data to the firebase system right if we want to go and add let's say another user score what we can do is we can say var add underscore task is a firestore task space equal to firestore underscore collection dot add and in this case i want to pull whatever our user's information is so i can say user.email right comma open braces and let's go name colon user.email comma score and let's say that their score is 30. all right and user i probably called it user data then i user info that's what i called a user info my apologies user info there we are and then once we have that firestore task so what a firestore tasks is the task for the fire store to do right so once we have that we're going to say var added user we're going to cast that as a firestar document we're going to say all right yield add underscore task comma task finished we're going to go ahead and print that doc that added user document so the first question is what are we doing here well what we're doing is we're creating a firestore task and then we're saying hey execute that task and wait until the task is finished and then once the task is finished grab the data it returned and print it simple enough right so what we'll do is we'll go ahead and put a break point here and we are going to try to authenticate so vic to atmaildrop.cc and then password1234 let's log in you'll see that we get our little success information then we'll say getscores all right so we've gotten all the way to here and we have our add user object so we got back our doc name with a dictionary score of 30 vic 2 atmaildrop.cc if we go back to our firebase and we go to our fire store you'll notice that there is a vic 2 at maildrop.cc and this is how simple this all is you can have a single username or single email and then have all of the user information associated with that user email in your database right here so i have their name and their score and then whatever else i want to put in here okay so what if we want to update our values here so first if we want to update our values with our database what we need to do is we need to right click here let's go ahead and add in a child node let's add in a button here and well i didn't mean to grab all that let's move this over here and just call it update score let me control a control c and paste in our update score here we're going to go ahead and hook that up like we've been doing earlier so let's go ahead and hook that up and then what we're going to do is we're going to say var firestore underscore collection we're going to cast that as a firestore collection and we're going to say that is equal to firebase.firestore dot collection and we're going to say user data we're going to return here we're going to say var update task is a fire store task and that's equal to buyer store collection dot update and we're going to say user.email and we're going to update our user email comma with a name colon user.email and then we're also going to update their score to be 100 awesome and finally we need to wait until that task is completed so var document you see up here how we did this right so actually let's just copy and paste this why waste the time coding it we can just paste it there we are and instead of get document we're going to wait until task underscore finished and we're going to grab our task here and we're going to wait until that is finished awesome so now if we go ahead and we refresh and we log in and we log in and we say get scores you'll see that um oh our email was not found so it's actually vic 2 and we'll log in you'll see we have success we'll get our scores and you'll see oh we got a null object value here and you'll see that we got a small error here and the reason why is because the document already exists so that's just something to keep in mind that you you don't want to send out a document if it already exists right so you probably should have it fetch the data and check if it already exists here but we'll continue through anyway and then we'll click update score you'll notice that we got nothing but if we go to our firebase you'll see that our score has been updated to 100 so it's that simple so now what if we want to run a small query on our database instead of actually just getting some scores or updating a value or something like that what if we want to go out and fetch a very specific score or very specific data what we can do is we can run a query so i'll go funk query db and we're going to say bar query is a firestore query and we're gonna make a new one so firestore query whoops dot new awesome and then we're gonna say query dot from we have from here we have to pick what document we want to get our data from so we're going to say from our user data document so you can see here our user data document and then we want to say hey let us get back our scores so query order by and then we're going gonna order by score comma firestore quarry dot direction dot ascending so what is this gonna do so what it's going to do is it's going to fire out a new query here it's going to query our user data table and it's going to get back the data with the score ascending so it's going to get us our scores ascending and we want to limit this right we don't want a thousands of scores right if let's say we're doing a scoreboard or something like that we don't want to get back a bunch of data but we only need a little bit right let's say we want to show the top you know five or ten people right so let's go query dot limit and let's say i'm going to limit it to the top three people and then what we're going to do is we're going to query that database so var query underscore task because we need to create a task to say hey we're going to do this and then we're going to say firestore task space is equal to firebase dot and i need a capital f here firebase dot firestore dot query and then we're going to pass in our query and then we need to wait until those results come back so we need to say var result is equal to yield whoops that's not what i'm looking for yield that query underscore task comma quote task finished and then we're to print our results awesome so what that will do is it'll go out and fetch out to the database query it and get back the top three results the best three scores so if we go back to our database and let's go ahead and add in two documents here so let's add in uh dnan and let's say dean in um name is deenan and let's say that his score is 200 well let's say 180. and then let's say the next person is momo and his name is momo let's add in a field and say score is equal to 500. momo's really good at this game so let's go ahead and save him so now if we go back here and we replace a breakpoint here and we refresh our page and we say vic to at maildrop.cc and we say password1234 we login so now we're logged in if we hit oh what we can't call it whoopsies that's my fault so let's add that in first so let's go add a a button let's bring that over here and say get top three scores all right and then we will rename this as get top scores awesome and then we're going to hook up our button and we will say get our top scores let's just query db awesome so now this is going to call here which is going to call this and it should return our results so let's go ahead and hit play let's say vic 2 at maildrop.cc and we will say password one two three four and we're gonna log in you'll see we got this little success here and then we're gonna say get our top three scores all right so we hit our break point that's good thing we have a dictionary result here of three so if we open up that dictionary in our inspector let's take a look at it no i guess it doesn't show up here it'll show up here though so if we open this up we get a hey code message the query result requires a group asn or asc index for collection user data fields you can create it here and then it gives you a massive link here so let's go ahead and get that massive link you can see here it also says hey uh you can't do that you need to create it here so let's grab this data here ctrl c and then let's go up here and paste it so you'll see that it's going to take us to firebase and what this is doing is it's adding an exemption so whenever you run a query on your database they don't allow you to immediately run it you need to say hey i'm allowing it to do this and it needs to index that data so let's go ahead and hit save and it's going to allow that ex that uh group scope to be allowed if that makes sense so if you were to look at this this is the exemption table how you get here is if you go to the cloud firestore data and you go to indexes single field it will take you to this area and you can add what's called exemptions and these are things that allows you to allow specific queries on your database in this case i usually just let firebase automatically detect and do it because i don't have any special needs but if you have any special needs you can go ahead and take a look at the documentation and it'll kind of run you through it but i'll get back to you guys once this is complete it's going to take a while so you can go ahead and get a cup of coffee or something all right so you can see that it has completed its indexing and its creation of this exemption so let's go back to godot and let's go ahead and re-fire that command off so get the top three scores go oh i need to let it finish so hold on let's go to debugger go and let's hit get top three scores now you'll see it'll stop here and look we've got a dictionary of three items here see so if we open them you'll see that there is a zero document size of field size of 2 and we have our score and our name so you can see 25 and then if we scroll down and we open up the next one and we go document fields name vic score of a hundred and then document or a dictionary document fields score 180 by a person named dna now you'll notice well hold on a minute momo's not in there or momo has 500 why is that the case well the reason why is because we need to do it of descending and now if we fire this off again so we refresh our project password one two three four and then we get our top three scores you'll see suddenly it fails again because we need to re-index our data here see again so let's go ahead and do that again and add in the ability to do descending see we need to add in descending so let's go ahead and add that so it's going to say here it's going to re-index so i'll see you guys in a moment all right so now that we got this let's go ahead and try her again get our top three scores click you'll see that it stopped you'll see that we have dictionaries again like we did last time and you can click on them and say our document fields and you'll see our first one is 500 and it is momo so that's exactly what we wanted so that's kind of the power of the querying system instead of us getting back all of the results like we did up here earlier when we were getting back our user data and then we had to go through and fetch the data i believe was right here we need to go and fetch specific people's information we could just go and query the entire database and pull back the data that we need now the last thing that i'm going to discuss is removing data let's say a user wants to delete their user data from your s your system you can actually just pull it out by running a remove document data function so let's say funk remove document data and then we'll say var firestore underscore collection is a firestore collection is equal to firebase dot capital f dot firestore dot collection and then we'll say user data again we're using if we go back to our data this information here so user data user data and then we're going to say var dl task and we're going to cast that as a firestore task is equal to a fire store collection dot delete and then we're going to say hey i want you to delete our user information so if we come up here and we see what our thing is userinfo dot email because that's our key that we've been using this entire time and then bar document firestore document is equal to yield delete task comma uh task finished and now we're going to go ahead and test this so we're going to put a button here so let's go right click add child node add in a button and then we're going to come down bring it down here i'm sure i'm upsetting some people with my messy button placement but so delete record and let's copy that and go ahead and paste it in here and get rid of that space there all right button up delete record connect and we're going to say i believe i called it remove document data all right so now if we go ahead and click that button when we log in so vic to at password1234 log in and delete record you'll see that we don't get anything back we don't get any confirmation or anything like that but if we go ahead and we check our database it has been removed so it's really that simple and finally what if they want us to delete the user itself we want to get rid of our user and we want to say hey we're done with this project we don't want to be here anymore right well what you can do is you can call a very simple call here so let's go ahead and add a button and let's call it remove user let's copy that go to our text and say remove user and let's expand this and put it down here by our forgotten password all right and on node say button up remove user and we're going to call a very simple function called firebase dot auth dot delete underscore user underscore account what that's going to do is going to take whatever authenticated user we have and it's going to go ahead and delete their account so let's fire this off and let's see how it goes so we'll say vic 2 at maildrop.cc password1234 we're going to log in and then we're going to click remove user all right we didn't get anything back it didn't say anything but if we go to our firebase authentication and we look vic 2 has been removed from our user accounts so i hope this kind of shows you guys the power of firebase and the power and how fast we can set up a simple user account setup and how we can set up a very simple firebase connection that's all i have for you guys today so we talked about uh creating an authentication system hooking up a new firebase project and we talked about how to save data to the firestore database [Music] so if you like this video go ahead and hit that like button if you dislike this video go ahead and hit that dislike button because i am here to make content for you guys now this was a viewer request out on reddit so you guys go ahead and hit me up on reddit or twitter or in the comments below anything that you guys want me to check out or you guys want me to talk about and i'll be more than happy to take a look at it because again i make content for you guys so that's all i have for you guys today i want to thank you guys for watching and i'll see y'all next time [Music] thanks [Music] you
Info
Channel: FinePointCGI
Views: 1,429
Rating: undefined out of 5
Keywords: firebase, firebase tutorial, firebase auth, firebase developers, godot firebase plugin, godot firebase, godot firebase tutorial, firebase database, firebase authentication, login page using firebase, godot engine firebase, firebase app, firebase login page, godot engine, godot google firebase, firebase login, firebase login tutorial, firebase authentication tutorial, firebase auth tutorial, godot game engine, Advanced Godot | Creating a Login Page With Firebase
Id: jKj57cXvViY
Channel Id: undefined
Length: 57min 15sec (3435 seconds)
Published: Mon Apr 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.