Last active
April 25, 2022 12:37
-
-
Save NoaTubic/1ffc85dafcbca112da2b56aeecc6b248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@LazySingleton(as: AuthRepository) | |
class AuthRepositoryImpl implements AuthRepository { | |
final FirebaseAuth _firebaseAuth; | |
AuthRepositoryImpl(this._firebaseAuth); | |
@override | |
Future<Either<AuthFailure, Unit>> signInWithEmailAndPassword({ | |
required EmailAddress emailAddress, | |
required Password password, | |
}) async { | |
final emailAddressString = emailAddress.getOrCrash(); | |
final passwordString = password.getOrCrash(); | |
try { | |
await _firebaseAuth.signInWithEmailAndPassword( | |
email: emailAddressString, | |
password: passwordString, | |
); | |
return right(unit); | |
} on FirebaseAuthException catch (exception) { | |
if (exception.code == 'wrong-password' || | |
exception.code == 'user-not-found') { | |
return left(const AuthFailure.invalidEmailAndPasswordCombination()); | |
} else { | |
return left(const AuthFailure.serverError()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment