Skip to content

Firebase phone auth returns: An internal error has occurred. [ Error code:39 ] #13187

Description

@thisisjamaldin

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Auth

Which platforms are affected?

Android, iOS

Description

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

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());
}

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!

Reproducing the issue

  1. init everything as said in docs.
  2. 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 {
    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;
    },
    );

Firebase Core version

3.3.0

Flutter Version

3.24.0

Relevant Log Output

> 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 ]

Additional context and comments

https://stackoverflow.com/questions/78875027/firebase-phone-auth-returns-an-internal-error-has-occurred-error-code39

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs AttentionThis issue needs maintainer attention.platform: androidIssues / PRs which are specifically for Android.platform: iosIssues / PRs which are specifically for iOS.plugin: authresolution: userThis was a user issue, e.g. invalid configuration or code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions