I am trying to make a notes app, on which i am trying to make user login based on "email and password" method of firebase. I have successfully designed a way to register user with email and password which is also shown on firebase console. Although, when trying to login by using "SignInWithEmailAndPassword" method, i am able to login with unregistered emails and password.
Here is the code,i am having problem in:
onPressed: () async {
try {
final checkuser =
auth.signInWithEmailAndPassword(
email: Email!, password: Password!);
if (checkuser != null) {
Navigator.pushNamed(context, MainScreen.id);
}
} catch (e) {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text('Login Alert'),
content: Text(
e.toString()),
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
}
},
Code is running good, there is no syntax error. Only Problem is unregistered users are also allowed to login.
2
Answers
So this was a dumb question, documentation has changed, i guess. The tutorial i followed for creating app has the problematic code that i have written above but as i was going through documentation of firebase thanks to a comment on the questions, i figured out the problem, so here is the updated code:
So here is the updated code. The code in the question, doesn't have "FirebaseAuthException" block with catch block, so that might be causing problem and letting unregistered user login. Thanks for everyone help!!!
Here is a solution to Firebase login: