I would like my app to only authenticate previously logged in users and not create new users. I'm using flutter and Firebase Authentication. I'm using google as a sign in method.
Ive searched the internet for a solution with no such luck. All of the examples i see create new users in the process
void _signInWithGoogle() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
setState(() {
if (user != null) {
_success = true;
_userID = user.uid;
print(user.displayName);
print(user.phoneNumber);
print(user.email);
} else {
_success = false;
}
});
}
I expected this to fail when there was a new user trying to login. but this seems to create a user and then log him in.