Android Java Firebase Authentication Tutorial 2020 | Registration, Login, Logout, Session, Profile

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to my channel in today's video i'm going to show you how you can implement firebase authentication using email and password in java so i'm getting a lot of emails to do some videos in java so this is my first video in java so hope you like it so just to i'm going to implement uh authentication with the login screen and the registration screen so let's start with first of all i'm going to rename the default activity with the name of login activity and let's add another activity which is i'm going to use for registration so i'll show you how you can implement firebase authentication login registration then session and how you can use the logout functionality as well so both the activities has added let it be sync now and now i'm going to implement the ui part so let's update our layout file so i'm simply adding one title then to edit text to take the input and one button which is going to call the firebase so first of all i'm implementing uh ui for the registration screen then we will simply copy and paste it on the login screen so this is just for the title and then one edit text for the input as a user email this is for password input and simply a button which is going to call register that's it and let's copy it and go to login activity and paste it and we'll just rename few things now again and input is same and button name is login that's it now before we implement our code let's go to our console so we need to register our console so simply type firebase authentication on the first link just click on it and on top right you can see go to console click on it enter your gmail credentials and you will land on this screen then click on this plus sign and give any name any project name so i'm giving firebase authentication java just to differentiate click on continue i'm just don't want any analytics click on this button it will take some time to create a project so hold up for some seconds yeah it's created now click on continue click on this android here we need to password package name so let's copy it from there and paste it here and then simply click on this button that's it and yeah now download this file google service json copy it and we need to come back to our project and then paste it inside the app folder the root folder of our project that's it then we don't need to make any modification in this class then close that now go to tools firebase now it will open another window and then click on authentication email and then i click on this button it will add all the dependencies in gradle file we can choose anyways we can add manually we can go to file project structure and then add it so it's up to you so once your project is a sync then go back to that assistance and then copy this code so code is already there we don't need to write much we just need to modification so which you are going to do then initialize it in our own create function import this package this i'm going to show you later and here it is so this is for registration let's go to our registration activity and so this function i'm creating is for the registration and then simply paste that and we need this variable firebase auth and we need to initialize that too same as we did it in login screen to get the instance of firebase auth we are going to call this register function on the button click of register let's simply import whatever is not there we now need this function removing it let's change it to our activity name and remove it remove this this that's it and it is showing a toast when it is failure but we are going to show a test when it is success as well so let's copy and paste it as well we are going to show the email id which is logged in logged in user email id so let's put it as well and bending it in the toast message itself now we need to handle our button click so it's simple button click in java and we need to call this register function and we need to pass what user has entered in the edit view as a user email and password so let's get those values as well so this is how we can read the value which is entered by user and the password as well and we need to make our edit text as a final and that's it for this class just simply close this so from login screen when user will come for registration once registration is done we see the success stores then it will close this activity now let's go to login activity and implement the same so we are similarly creating a separate function as login it is going to take the input email and password as a parameter and now we need to copy this function here so it's already available in your android sdk and that's it just copy it and paste it inside and do the same what we did for registration don't get confused both the code is looks similar but it's different because it's calling a different method of firebase name here we are going to show a toast when user will authenticate it successfully with the success message and if user is not authenticated then we'll show failed toast also on the success we are going to show the user email later i'll show how you can implement the session and the log out so just for the initial testing purpose i am going to show it on a toast now simply on login button click we need to implement it click listeners so let's do that we need to get the email what user is entered also the password what user has entered so let's get those too you first parameter is email and second parameter is password need to make this as final and to reach to the login registration screen i'm putting just one text view so as you have seen on many login screen if you don't have registered credential then they have registration link so similarly i am going to do that you so that is done now let's handle its click as well to start an activity so we can handle text view click listener as well similar to the button there you go and on click it we need to start an activity that is the registration activity there you go let's run it and see how it look like there you go so we can see our login screen and the relation link you can click and go to the registration screen but before we register we need to do one more step go to our console in the authentication click on this and click on this email password and enable it so until unless and until you will not enable it you won't be able to make a registration or authentication so this is very important step guys now run it again and see so on a login screen we click on register and i'm entering one email join it register and we see the toast and the email id so an activity got clause so we are successfully able to registered one account let's try to log in with that then the same password click on login so we can see the task as well there you go so we have successfully able to implement and here in console we can see that user as well that's great so let's create one more user donna gmail.com click on registered button now click there we go so one more user has registered and let's try to login with that there you go so we are successfully able to register to user and we can see those in the console and they are successfully authenticated as well so now let's add a profile activity so that we can see logged in user and there we will add a logout button so that user can login logout i am giving it as a profile activity so same as we need firebase auth object here too so i'm just copying and paste it and this firebase object will give us the current user current logged in user that is that will return the object of firebase user and that contains the email id now let's add one text view to display email id also i'm going to add a button to logout so that's the beauty of firebase you don't need to ask user to enter its credentials again and again uh until user click on the logout screen so instead of showing login screen again and again we can directly take him to the home screen or whatever screens you have in your project so ui part is done now let's extract all these button and text you in our activity and set the data and handle the click listener on this texture i'm going to show you the email and let's handle the logout button click listener and it's simply we need to just call one function that is known as sign out so firebase off dot sign out simple now we need to maintain the session so as our login screen is the launcher so it will always take you to the login screen but we can see if user is already logged in then send him to the profile activity so here we are going to handle that in the login activity override the onstart function and there we can check if we have any logged in user then take him to the profile activity so i am going to start a profile activity now we are on login activity dot this and we need to send it to profile activity dot class and we need to close login activity so simply call finish now call the same function when user is trying to login send him to profile activity as well let's run it and see since lonna is already logged in so it directly take me to the profile but when i click logout it did not close okay we did not do anything so we need to call our login activity yeah simple we need to call login activity and close the profile activity let's run and see since we click on our logout so now it take me to the login screen let's try to log in one more time there you go so john is able to successfully in and if i am closing my application and clicking on app icon that's not taking me to the login screen you can see the profile screen if i'm killing the app still it take me to the profile there you go i'm logged log out now and i'm closing up launching app it take me to the login screen let's see with the donor how's the behavior yes now clean the app relaunching it there you go there you go so guys thank you so much for watching this video if you have any question you can ask me in the comment section thank you please don't forget to subscribe like and share thank you
Info
Channel: LearningWorldz
Views: 2,827
Rating: undefined out of 5
Keywords:
Id: Ym6D1ukJSPw
Channel Id: undefined
Length: 27min 44sec (1664 seconds)
Published: Mon Oct 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.