Firebase Auth Exceptions handling | Flutter

Haroon Khan
Flutter Community
Published in
2 min readMay 29, 2020

--

Clear instruction messages on exceptions will save you from losing trusted users.

Pre-Reqs:

This guide expects you already know flutter basics, and if you don’t, then here is Flutter Learning Roadmap for you.

Background:

In this guide, I have modularized all the functionalities into different classes and enums with good practices to have maintainable and extendable code. All login and Result status handling logic is completely isolated from the UI.

Auth Result Status Enum:

Enums are very effective if you have multiple results statuses as in our case.
As the name suggests, AuthResultStatus will have the result status of firebase auth.

Auth Exception Handler:

As the name suggests, the AuthExceptionHandler class handles the exception by reading the error code of the firebase exception object, returns the AuthResultStatus based on the error code plus also generates an error message for every AuthResultStatus.

Firebase Auth Helper:

FirebaseAuthHelper class will handle the communication with Firebase Auth Service and just returns the result status to the UI. Through this class Authentication logic is isolated from the UI code.

Implementation:

Here is the final implementation for account creation and login. And based on the result status, either error dialog is shown or the user proceeds to the success page.

Closing Thoughts:

The complete GitHub project can be found here with a good UI plus some other best practices in the UI.
Looking forward to your thoughts, feedback for improvement.

If you want to get notified for future blogs, do connect on twitter, LinkedIn, and Github.

https://www.twitter.com/FlutterComm

--

--

Haroon Khan
Flutter Community

CTO AntonX | Full Stack Dev | Flutter & Node.js | DevOps | AWS