Although I have covered using Firebase Authentication with FirebaseUI, I figured I haven’t covered the traditional way of implementing Firebase Authentication which allows you to use your own authentication screen.

Back to the basics! This one is going to be quick and easy. You don’t want to waste time reading useless jargain and I don’t particularly feel like spending too long today on this. Let’s get to it.

This will cover how to perform Firebase Auth operations like signing in, signing up, and logging out. I assume you know how to make a UI with an EditText and a listener on it so none of that here.

Import the Dependency

Add this to your app-level  build.gradle file.

Initialise FirebaseAuth

If you try to do anything before initialising, crash goes your app.

Get Current User and User ID

These are the bread and butter methods of authentication: getting your user and his UID to use in the database, cloud messaging, or other stuff. If your user isn’t signed in, both of these will simply return null.

Signing Up New Users

Firebase Authentication allows you to use different authentication providers in your app. In the Firebase Console > Authentication > Sign-in Method, enable the providers you intend to use. (Note that for each, different setup will be required).

For now, we’ll only cover the standard email-password authentication provider. If you want me to cover how to authenticate with other providers like Facebook and Google, leave it in the comments.

Code snippet taken from the Firebase docs

Add this method to your submit button’s onClickListener or something. You pass in an email and password and I’m sure you can guess the rest.

Sign in Existing Users

Once again, this is just for the standard email-password provider.

Same story as signing up. You got the method, pass in the email and password and Firebase does the magic with callbacks for you to do your stuff when Firebase is done doing its stuff.

Accessing User Information

Code snippet taken from the Firebase docs

Once your user is signed in and the current user won’t be null, you can access information you’ll need to deliver a good app experience.