Login And SignUp using Firebase in Kotlin (Android Studio 2022) #androidstudio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to coding stuff and this is new tutorial series on firebase with kotlin and first of all we'll start with authentication so in this video we'll see how we can use firebase authentication with email and password in kotlin and in the next video we'll see how we can authenticate user with google sign-in and also with the phone authentication phone otp authentication and then after i will i'll make crud app with cloud firestore and real-time database so make sure you subscribe to channel for complete series so yeah i have created this empty project and first thing that you need to do you need to click on the tools select firebase here and it will open the uh firebase assistant and then i'll click on the authentication and click on the authentication using google or custom authentication any of this so as you can see my app is already connected to the firebase so just uh if your app is not connected just connect it click on this connect and then it will open the google chrome with your projects that you have in the firebase or you can create a new project as well i have added this app to the shop app which was our previous project so what we need to do so after connecting your app to the firebase you can click on this add the firebase authentication sdk to your app click on accept changes and it will add the dependency for authentication so till then what we can do in the shoe app project or your project you can click on this authentication and as you can see set up signing method click on this or you can click over here as well so i'll just make this email and password enable so click on that pin and enable click on save so yeah so as you can see no users for this project so it is empty so what we can do will open our android studio and the dependency has been set up correctly i guess so firebase auth and it says change to 2.1.3 it is which is the latest one and we'll use view binding here so for enabling the view binding what we need to do you just need to write build features and inside that we need to make view binding true and then i'll click on the sync now so our project is synced and i'll just close this and i have added some activities or two activities signing activity and signup activity the java code is blank and let me just walk you through its layout so i have already created these layouts let me just walk you through it i will be providing this source code in the description box so you you can just copy the xml code from there so it's just a background background image which i have created in the adobe xd and then this is the text input layout this one and as you can see i have added box stroke color as yellow and hint text color as yellow you'll notice this later when we install the app and i have provided it margin from the top of 300 dp and 16 dp margin horizontal and then inside the text input layout edit text we have this style and here also we have this style let me just click click on this and as you can see i have designed one style in which i just added margin top margin bottom width and height and for the inner uh layout width match pattern trap can contain text color max lines one and x all these properties let me just close this and then uh in the password input layout uh you can see i have added password toggle enable so this is the toggle that we can just uh or disable it and enable it if we enable it we can see the password if we disable it we cannot see the password so yeah and then this is the retype password edit text and then this is sign up method sign up button sorry which is app compact button and this is the text view so when user clicks on this will navigate user to the sign-in activity from the sign up and similarly in the sign in activity we have that text view we can just click on this and we will navigate user to the signup activity so yeah let's start with the manifest file first of all what we need to do we'll just copy this intent filter from here and i'm gonna paste it in the sign in activity and we need to make this exported true so this is the first activity that that will open when we install the app let me just close this and we'll close the activity main for now and we'll also close the sign-in activity we'll first start working with the signup activity so in the activity sign up we have three edit text as you can see and one button and the one text view so as we are using view binding here let's just initialize or let's just create a variable latent wire for binding so binding of type activity signup binding then over here we can just initialize our binding so binding equals to activity signup activity signup binding dot inflate and here we need to pass the layout inflator and instead of passing layout here what we can do we just delete this we can just write binding dot root and yeah we'll also create one lady network for firebase auth let's just name it as a firebase auth and over here we'll also initialize it so firebase auth instance now we'll use binding dot or button dot set on click listener [Applause] and as you can see if i click on this button this is navigating me to the signup activities button so yeah so if user clicks on this button what we need to do will create one valve for email so val email and binding dot text dot tostring so this emaility is this one and then after this we can again have another variable for password let's just name it as a pass and this will come from binding dot pass sat.text dot to string and we'll create another pass or another variable for password so come from pass this will be equals to binding dot com from pass et dot text and dot to string then we can have check for all of this if they are empty so it's not empty and pass is not empty and our come from pass is not empty then inside that we'll also have another check with pass equals to come from pass if this two are equals so yeah instead of doing this way we can just make it equals in kotlin we used to do it in java but kotlin also works with this kind of compare comparison so now uh if the if all the cases are satisfied means email is not empty and password is not empty confirm password is not empty and also password matches with the compound pass let's just provide else condition first so else if this happens then toast.make toast we can pass this here and we'll write password is not matching toes dot length short and dot show okay so then to this if condition we can provide another else which will be again the toast let me just copy it paste it over here and this will be empty fills are not allowed so now in the if condition if everything is okay then what we need to do just need to call the firebase auth dot create user with email and password and here we can pass email comma pass then we can add on complete listener to it and let me just close this and we will get auth result from here which is stored in it so we can just have one again one check with it dot successful if this is successful or if this fails so if that fails we can display another toast with it dot get exception dot to string and this will be happy so if the user creation is successful then we can send the user to the sign-in activity so we'll create one val contained this and another parameter will be sign in activity colon class dot java and then we can just start the activity so start activity and we'll pass in this intent so yeah this is how this will work now we'll move to this sign inactivity so inside the sign in activity okay we forgot to add this not over text view so just do it over here mining dot text view dot set on click listener so let me just show you the text so this is if already user is registered then we'll just navigate him to the sign-in activity so we can copy this intent or we can make separate method for that but will not do it over here and let's just press alt ctrl l which will format the code then we'll move to the sign-in activity similarly we'll create latent wire for binding which will be type of activity sign in banding this one again we'll create latent wire for firebase auth let's just initialize our binding so binding equals to activity sign in binding dot inflate and layout inflator then here binding dot root binding dot root then we can again binding dot text view will add on click listener to this text set on click listener and instead of this this will be sign up activity then we'll have binding dot button dot set on click listener we'll create one val we can just copy some code from here well let's copy it till here we'll paste it over here so as you can see we got error here because confirm password is not in the layout of activity sign in so this is how the view binding works it it will remove the null pointer exception in the runtime so we can just delete this and we don't need this if condition here you can remove this okay let's just press alt ctrl l we don't need this so instead of create user with email and password we can call the method which is sign in with email and password and then we pass email and pass will add on complete listener to it so if our user is signing successfully we'll send him to main activity dot colon colon class dot java and yeah and then other things will be similar okay so before installing the app we can go to the values in the themes i'll just make this as a no action bar and i'll change this color status by color i'll provide yellow here and now we'll try to run the app so our app is installed and so as you can see our app is installed and this is the sign-in page and if i try to write something here let me just write anything here and if i try to sign it so as you can see our app got crashed uh i guess we didn't initialize the firebase auth and the sign-in activity so yeah okay so let's just uh initialize it over here firebase auth equals to firebase auth dot get instance and we'll run the app application again and we'll see it's working or not so again it is installed so we don't have any user so if we try to hit right mail and password and then sign in it will again shows an exception in a toast so instead of that i'll click on the not registered yet sign up so it will take me to the sign up page and here i can just create one account so let me just write something here codingstuff0270 at the gmail.com this is our mail id if you want us to make a build app for you we can surely do that just hit mail to us then i'll set and password as coding one two three let me just click on this toggle and as you can see coding one two three let me just retype it coding one two three and again we'll make it visible so yeah so i'll click on this sign up so yeah i just successfully created the user let's just check the firebase console so as you can see coding stops zero seven zero i did it gmail.com which is the user signed in at april one created april one so yeah now we can just use that mail to sign in so coding stuff zero seven zero at the gmail.com i'll type in that password so coding123 and i'll hit on the sign in button so yeah the main activity started and this is how the firebase authentication with email and password works let's just try to run the app again and we'll see how does it looks now or how does it works so as you can see if the user is already logged in but still it is asking him to sign in or sign up so what we can do to avoid this in the sign-in activity we we override onstart method and here we can have one check in which will check if firebase auth dot current user is not equals to null then send the user to the main activity so we'll copy this and paste this so now if i try to run the app sign in activity will not open user will be navigated to the main activity so yeah and that's it for this video in the next video i'll make tutorial about how you can use google sign-in so yeah that's it do subscribe and thank you for watching
Info
Channel: CodingSTUFF
Views: 98,415
Rating: undefined out of 5
Keywords: android studio coding tutorial, android studio coding for beginners, android studio coding in flow, android studio coding with harry, android studio coding tutorial hindi, android studio coding with mitch, android studio coding for login page, android studio coding pdf, belajar coding android studio, android studio coding cafe, cara coding android studio, navigation drawer android studio coding in flow, android studio coding for calculator, coding stuff, codingstuff, stuff, coding
Id: idbxxkF1l6k
Channel Id: undefined
Length: 16min 56sec (1016 seconds)
Published: Fri Apr 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.