authUsersGoogle static method
Implementation
static Future<bool> authUsersGoogle(BuildContext context) async {
await Firebase.initializeApp();
final GoogleSignIn googleSignIn = GoogleSignIn();
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
GoogleSignInAuthentication? googleAuth;
GoogleSignInAccount? googleUser =
await (googleSignIn.signIn() as Future<GoogleSignInAccount?>);
if (googleUser != null) googleAuth = await googleUser.authentication;
if (googleAuth != null) {
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential logInUser =
await firebaseAuth.signInWithCredential(credential);
if (logInUser != null) {
// Check is already sign up
await ChatDBFireStore.checkUserExists(firebaseAuth.currentUser!);
final User? logInUser =
(await firebaseAuth.signInWithCredential(credential)).user;
/**
* Make user online
*/
await ChatDBFireStore.makeUserOnline(logInUser!);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
DashboardScreen(currentUserId: logInUser.uid)));
return true;
} else {
return false;
}
}
return false;
}