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:
- https://github.com/flutter/flutter/issues/25640 this didn't help me
- Flutter and google_sign_in plugin: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null) this is not quite related also didn't help me
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();