3

This is not a duplicate question and forums have no clear answer!

I'm getting error when I want to verify my phone via firebase authentication

E/FirebaseAuth( 9898): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Error code:39 I/flutter ( 9898): An internal error has occurred. [ Error code:39 ]

what have I done:

  1. Entered sha(1-256) keys to firebase console
  2. Enabled Phone and Google in sign-in method firebse console
  3. Added google-services.json to android/app and GoogleService-Info.plist to ios/Runner
  4. Added(auto) firebase.json to core location of project
  5. Enabled Play integrity in firebase console app check, entered debug and release sha256 keys
  6. Enabled Blaze payment in firebase
  7. Enabled Google Play Integrity API in google cloud console
  8. Upload to play store as Internal testing
  9. Waited 1 day to avoid quota exceed and to let configs take effects

My pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  flutter_localizations:
    sdk: flutter
  intl: ^0.19.0
  shared_preferences: ^2.3.1
  firebase_core: ^3.3.0
  firebase_auth: ^5.1.4
  flutter_bloc: ^8.1.6
  fluttertoast: ^8.2.8
  cloud_firestore: ^5.2.1
  image_picker: ^1.1.2
  firebase_storage: ^12.1.3
  mobile_scanner: ^5.1.1
  omni_datetime_picker: ^2.0.3
  pdf: ^3.11.1
  printing: ^5.13.1
  flutter_email_sender: ^6.0.3
  pretty_qr_code: ^3.3.0
  url_launcher: ^6.3.0
  firebase_app_check: ^0.3.0+4

My project build.gradle:

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.4.2"
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

My app build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    localProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace "com.---.----" //I hide this here
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.---.----" //I hide this here
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 23
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    
    signingConfigs {
        release {
            keyAlias localProperties['keyAlias']
            keyPassword localProperties['keyPassword']
            storeFile localProperties['storeFile'] ? file(localProperties['storeFile']) : null
            storePassword localProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.1.2')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-appcheck-playintegrity'
}

My main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.white, // navigation bar color
    statusBarColor: Colors.white, // status bar color
    statusBarIconBrightness: Brightness.dark, // status bar icons' color
    systemNavigationBarIconBrightness:
        Brightness.light, //navigation bar icons' color
  ));
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  await FirebaseAppCheck.instance.activate();
  runApp(const MyApp());
}

My code to verify:

void _verifyPhone(AuthVerifyPhoneEvent event, emit) async {
    await FirebaseAuth.instance.setSettings(appVerificationDisabledForTesting: false);
    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: event.phone,
      verificationCompleted: (PhoneAuthCredential credential) async {
        await FirebaseAuth.instance.signInWithCredential(credential);
        _onVerificationComplete();
      },
      verificationFailed: (FirebaseAuthException e) {
        if (e.code == 'invalid-phone-number') {
          add(AuthEmitStateEvent(
              state: state.copyWith(error: "invalidPhoneNumber")));
        } else {
          ------ I get this to work ------
          print("---error:${e.message}");
          add(AuthEmitStateEvent(state: state.copyWith(error: e.message)));
        }
      },
      codeSent: (String verificationId, int? resendToken) {
        this.verificationId = verificationId;
        add(AuthEmitStateEvent(state: state.copyWith(pages: Pages.Code)));
      },
      codeAutoRetrievalTimeout: (String verificationId) {
        this.verificationId = verificationId;
      },
    );
  }

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on macOS 13.6.7 22G720 darwin-x64, locale en-KG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.92.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!
1
  • in some devices I get: An internal error has occurred. [ API key not valid. Please pass a valid API key. ] Commented Aug 15, 2024 at 17:20

3 Answers 3

4

I think the country is blocked, or It looks like some phone carriers(numbers providers) are blocking SMS with URLs

Sign up to request clarification or add additional context in comments.

2 Comments

Even though your answer might be correct, it would be helpful if you provide supporting documentation to your answer so that reviewers can verify the authenticity. For example in this case, it would be helpful to provide a documentation link which explains the meaning of Error code: 39.
I have contacted Firebase and phone carriers, Firebase said it might be because carriers ban Firebase which was confirmed by carriers, they asked Firebase phone number which they use to send SMS to unban it, I didn't try to get deeper.
0

Firebase Error 39

According to the enum on Firebase Documentation, 39 translated to QuotaExceeded

https://firebase.google.com/docs/reference/unity/namespace/firebase/auth

Under Firebase Console, we can find a settings under Authentication > Settings > Sign-up quota

By default, firebase rate limits your requests on an account level to 100/hour, once exceeded, a not very verbose error returns: "Error 39, backendError"

Resolution

As this rate limit can only be increased to a maximum of 7 days, if you forecast heavy use like an upcoming event, you would need to manually come into this settings and increase it

Comments

-1

i have the same issue. the same version of Firebase. that is in release version in Android and IOS in TestFlight

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
That was because my sim-card operator was blocking firebase thinking it is spam sender

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.