This file contains hidden or 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
| abstract class AuthRepository { | |
| Future<Either<AuthFailure, Unit>> signInWithEmailAndPassword({ | |
| required EmailAddress emailAddress, | |
| required Password password, | |
| }); | |
| } |
This file contains hidden or 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, |
This file contains hidden or 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
| Future<User> signInOrCreateAccount( | |
| BuildContext context, Future<UserCredential> Function() signInFunc) async { | |
| try { | |
| final userCredential = await signInFunc(); | |
| await maybeCreateUser(userCredential.user); | |
| return userCredential.user; | |
| } on FirebaseAuthException catch (e) { | |
| ScaffoldMessenger.of(context).hideCurrentSnackBar(); | |
| ScaffoldMessenger.of(context).showSnackBar( | |
| SnackBar(content: Text('Error: ${e.message}')), |
This file contains hidden or 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
| Future<User> signInWithEmail( | |
| BuildContext context, String email, String password) async { | |
| final signInFunc = () => FirebaseAuth.instance | |
| .signInWithEmailAndPassword(email: email.trim(), password: password); | |
| return signInOrCreateAccount(context, signInFunc); | |
| } |