Implementing Firebase Login Authentication - noojman/Test-Prep-Grading-App GitHub Wiki

Firebase provides us with an elegant solution for handling user accounts and information. Not only does it include secure creation and authentication of user accounts, it also includes a secure database for structured data and direct file downloads.

To use Firebase Authentication in an Android Project, the app must first be registered with Firebase using the correct Android package name. For example, in this application, the name is com.noojman.testprepgradingapp.

Then, download the google-services.json configuration file and move it into the module (app-level) directory of the app.

Now, the root-level (project-level) build.gradle file needs some additional rules to include the Google Services plugin.

 buildscript {

      repositories {
           // Check that you have the following line (if not, add it):`
           google()  // Google's Maven repository`
      }

      dependencies {
           // ...

           // Add the following line:`
           classpath 'com.google.gms:google-services:4.0.1'
      }
 }

 allprojects {
      // ...

      repositories {
           // Check that you have the following line (if not, add it):
           google()  // Google's Maven repository
           // ...
      }
 }

The module (app-level) build.gradle file also needs some changes as well, as follows:

 apply plugin: 'com.android.application'

 android {
      // ...
 }

 // Add the following line to the bottom of the file:
 apply plugin: 'com.google.gms.google-services'

Finally, in the same build.gradle file (app-level), add the dependency for the core Firebase SDK.

 dependencies {
      // ...
      // add these two implementation dependencies - firebase-auth for authentication:
      implementation 'com.google.firebase:firebase-core:16.0.9'
      implementation 'com.google.firebase:firebase-auth:17.0.0'

      // add this line to use Firebase Cloud Firestore database
      implementation 'com.google.firebase:firebase-firestore:19.0.2'
 }

Now, don't forget the Firebase import at the top of the file and you should be good to go. For example, my Login screen uses these three imports:

 import com.google.firebase.auth.AuthResult;
 import com.google.firebase.auth.FirebaseAuth;
 import com.google.firebase.auth.FirebaseUser;

These imports will vary depending on your use cases. Now you are ready to begin using Firebase Authentication (and other Firebase features) in your Android application!