signInWithGoogle method
Future<User?>
signInWithGoogle(
)
Implementation
Future<User?> signInWithGoogle() async {
try {
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
// Check if the user canceled the sign in
if (googleAuth == null) {
debugPrint(
"${FirebaseAuthException(code: 'canceled', message: 'User canceled sign in')}");
return null;
}
final googleAuthCredential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential credential = await FirebaseAuth.instance
.signInWithCredential(googleAuthCredential);
User? user = credential.user;
// state = AsyncData(user.displayName);
// state = AsyncData(_currentUser.email);
return user;
} catch (e, s) {
debugPrint("[[Error on Riverpod signInWithGoogle]]: $e");
debugPrint("[[StackTrace]]: $s");
return null;
}
}