Implementing Firebase in Flutter is a straightforward process, you install firebase core, config it and then install Firebase Authentication. However, in my experience, I found documentation is a separate piece that I have to connect I have to connect them myself. I will list the step I took and links to official/unofficial docs to implement and solve problems I found in this article.
Content
Install Firebase Core
- Configure Firebase for your flutter project
Install Firebase Auth and implement it with Riverpod.
Implement Google Sign-in
- Fix an error on debug version of Android.
Install Firebase Core
Install Firebase core and init firebase project in Flutter.
The first guide to follow: https://firebase.google.com/docs/flutter/setup?platform=ios
Problem found when running:
flutterfire configure
- Flutterfire not found. Need to specify a new path.
flutterfire configure
will generate config files for each platform.- need to run again whenever adding a new platform or adding more firebase packages.
Installing firebase auth.
https://firebase.google.com/docs/auth/flutter/start
- Implement firebase_auth with Riverpod guide: https://bishwajeet-parhi.medium.com/firebase-authentication-using-flutter-and-riverpod-f302ab749383
Implement sign-in with google.
https://pub.dev/packages/google_sign_in,
Follow each step carefully, as they have a specific setup for each platform.
on iOS, however, it is required that app must have a 'sign-in with apple' option to be approved on the app store.
Problem found
The application throws an error when finishing sign-in with google screen in Android.
This happens in debug version on Android. While do not have any issues on iOS.
The root cause is, We need to add a "debug" version of the fingerprint in the Firebase console android app. The one that we successfully created is only for the production version of android.
https://developers.google.com/android/guides/client-auth?authuser=0&hl=en
Get debug certificate fingerprint.
Problem found: cannot run keytool command, need to install java...
- install java... from java.com
Following the guide, I use this command to get the debug.keystore. Since my app already publishes I can get the production keystore directly from Google Play Console.
keytool -list -v \
-alias androiddebugkey -keystore ~/.android/debug.keystore
- Then add debug keys from the result to SHA certificate fingerprint for Android application in Firebase. The app now sign-in successfully with Google on debug version of Android.
The most tedius process for me was to figure out what was the real problem that the error occurs. As the requirement is not clearly state in google_sign_in package but in google play service clieth auth guideline which is right. However a link as useful resources in pacakge would save so much time from googling. Hope this article helpful for who might try implementing Firebase Auth for very first time. Cheers!