1

Please read the question before sitting it to duplicate

I'm trying to make google sign in feature in my app but this error keeps showing up

I've done the following:

  • added support email
  • activated google signin in flutter console
  • generated the sha1 and signed it to firebase
  • added the following dependencies:
    • firebase_core: ^0.4.0+6
    • firebase_auth: ^0.11.1+8
    • google_sign_in: ^4.0.4
    • rxdart: ^0.22.0
    • cloud_firestore: ^0.12.7
  • updated gradle to version 5.1.1 (latest for the time being posted)

what I already tried:

here is the brains of the app

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

class AuthService {

  final GoogleSignIn _googleSignIn = GoogleSignIn();
  final FirebaseAuth _auth = FirebaseAuth.instance;
  final Firestore _db = Firestore.instance;

  Observable<FirebaseUser> user;
  Observable<Map<String, dynamic>> profile;
  PublishSubject loading = PublishSubject();

  AuthService() {
    user = Observable(_auth.onAuthStateChanged);

    profile = user.switchMap((FirebaseUser u) {
      if (u != null) {
        return _db
            .collection('users')
            .document(u.uid)
            .snapshots()
            .map((snap) => snap.data);
      } else {
        return Observable.just({});
      }
    });
  }

  Future<FirebaseUser> googleSignIn() async {
    loading.add(true);

    GoogleSignInAccount googleUser = await _googleSignIn.signIn();

    GoogleSignInAuthentication googleAuth = await googleUser.authentication;

    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );

    final FirebaseUser user = await _auth.signInWithCredential(credential);
    print("signed in " + user.displayName);

    updateUserData(user);

    loading.add(false);
    print("signed in " + user.displayName);
    return user;
  }

  void updateUserData(FirebaseUser user) async {
    DocumentReference ref = _db.collection('users').document(user.uid);

    return ref.setData({
      'uid': user.uid,
      'email': user.email,
      'photoURL': user.photoUrl,
      'displayName': user.displayName,
      'lastSeen': DateTime.now()
    }, merge: true);
  }

  void signOut() {
    _auth.signOut();
  }
}

final AuthService authService = AuthService();
Basel Abuhadrous
  • 1,444
  • 1
  • 14
  • 30

2 Answers2

1

I found the answer here https://github.com/flutter/flutter/issues/33393#issuecomment-510395178 you don't have to add the links listed in the comment, just update the picture with anything and it will work

the docs needs to be updated

Basel Abuhadrous
  • 1,444
  • 1
  • 14
  • 30
1

For me adding scopes and hostedDomain in GoogleSignIn method works.

final GoogleSignInAccount? googleUser = await GoogleSignIn(
        scopes: ['email', 'profile'],
        hostedDomain: '',
      ).signIn();