I am following a YouTube video of creating a Social Media App with Flutter and Firebase.
But in Authentication part Firebase is logging in the user even if the email entered by the user is not registered in the database.
Firebase also logs in the user if the email is registered in the database but the password entered is wrong.
Here is my Authentication.dart where I have all the Authentication stuff:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
class Authentication with ChangeNotifier {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn();
String userUid;
String get getUserUid => userUid;
Future logIntoAccount(String email, String password) async {
UserCredential userCredential = await firebaseAuth
.signInWithEmailAndPassword(email: email, password: password);
User user = userCredential.user;
userUid = user.uid;
print(userUid);
notifyListeners();
}
Future createAccount(String email, String password) async {
UserCredential userCredential = await firebaseAuth
.createUserWithEmailAndPassword(email: email, password: password);
User user = userCredential.user;
userUid = user.uid;
print('Created account Uid => $userUid');
notifyListeners();
}
Future logOutViaEmail() {
return firebaseAuth.signOut();
}
Future signInWithGoogle() async {
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential authCredential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken);
final UserCredential userCredential =
await firebaseAuth.signInWithCredential(authCredential);
final User user = userCredential.user;
assert(user.uid != null);
userUid = user.uid;
print('Google User Uid => $userUid');
notifyListeners();
}
Future signOutWithGoogle() async {
return googleSignIn.signOut();
}
}
Please guide me by checking if there is something wrong in the Authentication part.