starleaf1
starleaf1

Reputation: 2872

Error when using Firebase Auth Emulator with Flutter

I'm getting this error when trying to use Google Sign-in with Firebase Emulators

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/unknown] An internal error has occurred. [ The Auth Emulator only support sign-in with google.com using id_token, not access_token. Please update your code to use id_token.

My sign-in code is copied almost verbatim from Firebase docs

import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

Future<UserCredential> signInWithGoogle() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

  // Obtain the auth details from the request
  final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;

  // Create a new credential
  final credential = GoogleAuthProvider.credential(
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );

  // Once signed in, return the UserCredential
  return await FirebaseAuth.instance.signInWithCredential(credential);
}

This only shows up when hooked up to Emulator suite and not when using real Firebase instance.

Is there a workaround or fix?

Flutter Doctor output

[✓] Flutter (Channel stable, 3.16.8, on Ubuntu 22.04.3 LTS 6.5.0-21-generic, locale en_US.UTF-8)
    • Flutter version 3.16.8 on channel stable at /home/starleaf1/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 67457e669f (6 weeks ago), 2024-01-16 16:22:29 -0800
    • Engine revision 6e2ea58a5c
    • Dart version 3.2.5
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/starleaf1/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/starleaf1/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2023.1)
    • Android Studio at /home/starleaf1/android-studio
    • Flutter plugin version 78.0.1
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /home/starleaf1/android-studio
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version unknown)
    • VS Code at /snap/code/current
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    ✗ Unable to determine VS Code version.

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Ubuntu 22.04.3 LTS 6.5.0-21-generic
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 121.0.6167.184

[✓] Network resources
    • All expected network resources are available.

• No issues found!

The Firebase integration was initialized using FlutterFire CLI

Upvotes: 2

Views: 562

Answers (2)

mabg
mabg

Reputation: 2090

  • Put google-services.json on android/app

  • On android/build.gradle add on dependencies:

    dependencies {
       classpath 'com.google.gms:google-services:4.3.15'
       ...
    }
    
  • On android/app/build.gradle add before android:

     apply plugin: 'com.google.gms.google-services'
    
     android {
       ...
    

Upvotes: 0

codrikaz
codrikaz

Reputation: 293

  1. first off all check the json file in your android/app/google-services.json

enter image description here

  1. clarify in firebase account google signing enabled or not?

enter image description here

  1. lastly change the ssh in your firebase console

try this -

./gradlew signingReport 

make sure run the particular command on android directory

Upvotes: -2

Related Questions