signInWithGoogle method
Future<UserCredential>
signInWithGoogle(
{ - bool retry = true,
})
Implementation
Future<UserCredential> signInWithGoogle({bool retry = true}) async {
late UserCredential c;
try {
if (kIsWeb) {
GoogleAuthProvider googleProvider = GoogleAuthProvider();
c = await FirebaseAuth.instance.signInWithPopup(googleProvider);
} else if (Platform.isWindows) {
verbose("Logging in with GSToken on Windows");
c = await signInWithGoogleWindows(retry: retry);
} else {
GoogleSignInAccount? googleUser =
await GoogleSignIn.standard().signIn();
GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
if (googleAuth == null) {
error("Google Auth is null!");
}
OAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth?.accessToken,
idToken: googleAuth?.idToken,
);
c = await FirebaseAuth.instance.signInWithCredential(credential);
}
Map<String, dynamic> profile = c.additionalUserInfo?.profile ?? {};
String? firstName = profile["given_name"] ?? extractFirstName(c.user!);
String? lastName = profile["family_name"] ?? extractLastName(c.user!);
//String? profilePictureUrl = profile["picture"];
verbose("Google First Name: $firstName");
verbose("Google Last Name: $lastName");
svc<UserService>().grabName(firstName, lastName);
} catch (e, es) {
error("Failed to sign in with Google!");
talker.handle(e, es, "Google Sign In Failed!");
}
return c;
}