I'm trying to hook the Firebase Authentication emulator to my Flutter mobile project to perform some local testing. Unfortunately it seems it is not possible to do with the FlutterFire plugin.
There is no problem whatsoever to enable Firestore or Cloud Functions emulators, but I can not find a way for Authentication.
Is there someone with ideas or best practices to follow?
It looks like the method to connect to the Authentication emulator hasn't made it to the FlutterFire libraries yet.
An issue was logged for it in the Github repo, so you can follow its status there.
Update: It looks like this has now landed in version 0.20 (and later) of the firebase_auth package. The syntax should be something like:
FirebaseAuth.instance.useEmulator('http://localhost:9099');
It is now available in the latest stable release (^0.20.1).
To use it, call FirebaseAuth.instance.useEmulator('http://localhost:9099')
It must be called prior to accessing any auth methods.
Configuring flutter app to work with firebase authentication in local emulators.
First:
Add one of the below lines before authentication function call see which one working for me loopback IP worked:
firebaseAuth.useAuthEmulator('127.0.0.1',9099);
//firebaseAuth.useAuthEmulator('http://localhost',9099);
Sample:
Future<LocalUser?> signInAnonymously({required BuildContext context}) async {
firebaseAuth.useAuthEmulator('127.0.0.1',9099);
//firebaseAuth.useAuthEmulator('http://localhost',9099);
UserCredential userCredential = await firebaseAuth.signInAnonymously();
return LocalUser(user: userCredential.user);
}
If you get network error do as follow.
Second-1: For Android.
Add android:usesCleartextTraffic="true" in AndroidManifest.xml path: android/app/src/main/AndroidManifest.xml.
<application
android:usesCleartextTraffic="true" //<========
android:name="io.flutter.app.FlutterApplication"
android:label="firebaseauthexample"
android:icon="#mipmap/ic_launcher">
Second-2: For IOS.
Add bellow code here ios/Runner/Info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Firebase emulator has support to connect to web apps. *As a workaround, you can use the beta version of flutter to convert your mobile app to web app and test your it in your browser. You would have to add support for firebase services explicitly in index.html file.
See: -
https://flutter.dev/web
https://flutter.dev/docs/get-started/web
"localhost" may be easier to use as follows:
Flutter has updated useEmulator with useAuthEmulator. To use local Authentication emulator, you can use useAuthEmulator method by passing Firebase emulator port and "localhost" keyword as follows:
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
Please be sure to pass this line before all auth methods as mentioned by #frank-van-puffelen before.
Related
I've added all dependencies like:
firebase_core: ^2.5.0
firebase_auth: ^4.2.6
And also setup Firebase console perfectly after running it was showing error.
for solving this go to firebase and open the project you are adding into your app then go to the feature that your adding in your app for example :- (authentication) when you open authentication in firebase on the top you’ll see the rules option click on it and then change your rules.. by default rules don’t allow to read/write but we want to change this to allow..
I implemented google login in flutter without using firebase in flutter (google cloud console). It was working in apk then later I needed push notification service for which I used firebase (fcm token and all) then I released the app to playstore but google login does not work. I keep getting apiexception error. Has anybody faced this issue? if yes any help would be highly appreciated.
I do not have a specific answer to your problem but I have also faced this problem once, I accidentally resolved it though.
But Error 12500 is a general error code that may occur when attempting to use the Google Sign-In feature and is caused by a few potensial issues:
An issue with the SHA-1 fingerprint of your app's signing
certificate: To use Google Sign-In, you need to configure your app's
SHA-1 fingerprint and package name in the Firebase console. Make
sure that the fingerprint and package name you have configured in
the Firebase console match the ones you are using to sign your app.
An issue with the Google Services configuration file: Make sure you
have properly added the Google Services configuration file to your
app.
An issue with the Google Play Services library: Make sure you have
the latest version of the Google Play Services library installed in
your app.
An issue with the device or emulator you are using: Make sure you
are testing on a device or emulator that has Google Play Services
installed and is up to date.
Possible fixes to try/check:
Double-check the SHA-1 fingerprint and package name: Make sure that
the SHA-1 fingerprint and package name you have configured in the
Firebase console match the ones you are using to sign your app.
Make sure you have added the Google Services configuration file: The
Google Services configuration file is required for your app to
communicate with Google services, including Google Sign-In. Make
sure you have properly added this file to your app.
Update the Google Play Services library: Make sure you have the
latest version of the Google Play Services library installed in your
app. You can check for updates by going to the "SDK Manager" in
Android Studio.
Test on a device or emulator with Google Play Services installed:
Make sure you are testing on a device or emulator that has Google
Play Services installed and is up to date.
I hope this helps! I will quickly search if I can find any other solution.
Login and Registration aren't working on the apk that we build, but it works on the emulator, and it works when it's connected with a cable to a real phone.
Any ideas?
We haven't changed anything considering login.(controllers, service, ect.) and we are using android phones
We are also using GetX if that matters.
Is it some android permission or something?
You might forget the internet permission in Android Manifest.
in your AndroidManifest.xml file, add the below line inside <manifest></manifest>
<uses-permission android:name="android.permission.INTERNET"/>
I saw documentation for flutter firebase Appcheck
what do I need to do in release mode with an original certificate?
because all it says is for website verification
await FirebaseAppCheck.instance.activate(webRecaptchaSiteKey: 'recaptcha-v3-site-key');
I am unable to understand what to add in code for making use of app check in flutter
I think that code is only for the web platform.
For android open your main project directory in the terminal and follow the steps below.
flutter> cd .\android\
flutter\android> .\gradlew signingReport
This will print all your keys. Find the applicable one that you want. Then, copy the SHA-256 into the correct place in the firebase console.
We have an app connected to the internet.
Building a release APK is working and the app is connected to the internet.
Building a App Bundle, uploading it in the Google Play store and
installing it via Google Play the app is running but gets no connection to the internet.
downloading the apk via the App Bundle Explorer in the Google Play Console the app is running but gets no connection to the internet.
I also see the android.permission.INTERNET is set...
What can be the problem in my case?
<application android:label="APP_NAME" android:usesCleartextTraffic="true" //Add This>
</application>
<uses-permission android:name="android.permission.INTERNET"/> //Add This
Few Options I can think of:-
1. Build the apk from aab you uploaded on play. (test its behaviour)
2. Check that the flavor you are building, it doesn’t override settings, by having its own manifest.
3. Test on different devices.
4. See if there are any certificates installed.
5. Reverse Engineering (Last Option)
I found out the problem is not about the connection to the internet itself - the problem seems to be inside the flutter_secure_storage - but only when deployed in Google Play Store...
After updating flutter_secure_storage to the latest version the problem was gone.
10/2022
Hi guys, I faced with this error and the real problem came from flutter_secure_storage and shared_preferences. You guys need to add:
android:allowBackup="false" android:fullBackupContent="false"
to Androidmanifest.xml like this issues!
There is a manifest file in this directory
android/app/src/debug/AndroidManifest.xml
Copy the internet permission from above directory and to add the internet permission in this directory
android/app/src/main/AndroidManifest.xml