Every time I tried logging into Google with GoogleSignIn, my real ios simulator would crash. I would not get a debug message, and running it through the debugger produced nothing. Here is my code:
@override
Future<Either<Failure, MemberEntity>> getGoogleSignIn() async {
try {
//* Desktop */
if (UniversalPlatform.isLinux ||
UniversalPlatform.isWindows ||
UniversalPlatform.isMacOS) {
try {
final provider =
DesktopOAuthManager(loginProvider: LoginProvider.google);
final memberEntity = await provider.login();
if (memberEntity.memberName != 'Guest') {
return Right(memberEntity);
} else {
return Left(GoogleSignInFailure());
}
} catch (e) {
return Left(GoogleSignInFailure());
}
} else
//* Web */
if (UniversalPlatform.isWeb) {
final GoogleAuthProvider googleProvider = GoogleAuthProvider();
final UserCredential userCredential =
await FirebaseAuth.instance.signInWithPopup(googleProvider);
final user = userCredential.user;
if (user != null) {
final memberEntity = MemberEntity.social(
user.displayName!, user.email!, user.photoURL!, user.uid);
return Right(memberEntity);
} else {
return Left(GoogleSignInFailure());
}
//* ios, android */
} else {
// Trigger the authentication flow
final GoogleSignInAccount? _googleSignIn = await GoogleSignIn(
scopes: [
'email',
'profile',
],
).signIn();
final user = _googleSignIn;
if (user != null) {
final memberEntity = MemberEntity.social(
user.displayName!, user.email, user.photoUrl!, user.id);
return Right(memberEntity);
} else {
return Left(GoogleSignInFailure());
}
}
} catch (e) {
print(e);
}
return Left(GoogleSignInFailure());
}
After some research on the google_sing_in() package from the pub.dev, I realized I was missing the clientId in the /* ios, android */ section of GoogleSignIn(). I inserted the clientId and Poof - it works fine now. It took me hours to figure that out. Final code:
... //* ios, android */
} else {
// Trigger the authentication flow
final GoogleSignInAccount? _googleSignIn = await GoogleSignIn(
clientId: GOOGLE_IOS_OAUTH_CLIENT_ID,
scopes: [
'email',
'profile',
],
).signIn();
final user = _googleSignIn;
if (user != null) {
final memberEntity = MemberEntity.social(
user.displayName!, user.email, user.photoUrl!, user.id);
return Right(memberEntity);
} else {
....
I haven’t tried this on android yet, but a wooden nickel says I will need to split that } else { into an individual check for IOS and one for ANDROID to pass the unique client ID of each.