signInWithEmail method
Signs in a user with email and password.
email: The user's email address.password: The user's password.
Returns the User object on success, or null on failure.
Implementation
Future<User?> signInWithEmail(String email, String password) async {
try {
UserCredential userCredential = await auth.signInWithEmailAndPassword(
email: email,
password: password,
);
return userCredential.user;
} on FirebaseAuthException catch (e) {
// Log specific error messages based on the Firebase error codes
switch (e.code) {
case 'user-not-found':
print('No user found for the provided email.');
break;
case 'wrong-password':
print('Incorrect password provided.');
break;
default:
print('Error signing in with email: ${e.message}');
}
return null;
} catch (e) {
print('Unexpected error signing in with email: $e');
return null;
}
}