Today I am discussing how to authenticate your Flutter app using 'flutter firebase auth', specifically, Google sign-in with Flutter because it is the most commonly used firebase_auth method.
First, lets start with adding required dependencies to your project.
Note: Make sure you are installing the latest 'firebase_auth' and 'google_sign_in' libraries.
Now, we are going to configure the Firebase console. If you haven’t set up your Firebase account yet, log in to Firebase with your Gmail account, and create a project in the console.
Now you need to go to the authentication tab as shown in the above image. Enable Google authentication from the Sign-in provider’s list. Then you will be asked to follow some steps to enable authentication. Follow those instructions.
Now let’s start implementing firebase_auth in our application.
Below code will authenticate your user and return the current user.
Now, we have implemented functions to sign-in and sign-out with Google authentication. However there is no need for the user to log-in every time the application is open. Therefore we have to modify this to address the currently logged-in user.
With the above code, you can access the currently logged-in user at the splash screen in your app. Then you can decide to display either the login UI or the main screen. Now we have all the functions that we need to authenticate the user.
This is where you can decide whether to display the login screen or not.
Now, I am going to implement a sample log-in screen with 'google sign-in flutter'.
This is all you have to do to implement 'firebase auth' in your Flutter app. I hope you enjoyed this coding tutorial! If there are any questions, use the comments section below.