loginWithEmailAndPassword method
- String email,
- String password,
- BuildContext context, {
- dynamic onMFA(
- dynamic resolver
Log in with email and password.
Returns a LoginResponse with the user object if the login was
successful. If the login was not successful, the response will
contain an Error object with the error title and message.
Implementation
@override
Future<LoginResponse> loginWithEmailAndPassword(
String email,
String password,
BuildContext context, {
// ignore: avoid_annotating_with_dynamic
Function(dynamic resolver)? onMFA,
}) async {
try {
var credential = await auth.signInWithEmailAndPassword(
email: email,
password: password,
);
return LoginResponse(
loginSuccessful: credential.user != null,
userObject: credential.user,
);
} on FirebaseAuthException catch (e) {
loginError = switch (e.code) {
'user-disabled' => LoginResponse(
userObject: null,
loginSuccessful: false,
loginError: Error(
title: translationsService.userDisabledMessage,
message: translationsService.userDisabledMessage,
),
),
'wrong-password' => LoginResponse(
userObject: null,
loginSuccessful: false,
loginError: Error(
title: translationsService.wrongPasswordTitle,
message: translationsService.wrongPasswordMessage,
),
),
'too-many-requests' => LoginResponse(
userObject: null,
loginSuccessful: false,
loginError: Error(
title: translationsService.tooManyRequestsTitle,
message: translationsService.tooManyRequestsMessage,
),
),
'invalid-credential' => LoginResponse(
userObject: null,
loginSuccessful: false,
loginError: Error(
title: translationsService.invalidCredentialsTitle,
message: translationsService.invalidCredentialsMessage,
),
),
_ => LoginResponse(
userObject: null,
loginSuccessful: false,
loginError: Error(
title: translationsService.errorMessage,
message: translationsService.errorMessage,
),
),
};
}
return loginError!;
}