Skip to content

Instantly share code, notes, and snippets.

@NoaTubic
Last active April 25, 2022 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoaTubic/1ffc85dafcbca112da2b56aeecc6b248 to your computer and use it in GitHub Desktop.
Save NoaTubic/1ffc85dafcbca112da2b56aeecc6b248 to your computer and use it in GitHub Desktop.
@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