로그인 버튼 함수
UserController.to.login(_email.text.trim(), _password.text.trim());
UserController
Future<void> login(String email, String password) async {
String result = await _userRepository.login(email, password);
if (result == "success") {
print("success");
} else if (result == "user-not-found") {
print('No user found for that email.');
} else if (result == "wrong-password") {
print('Wrong password provided for that user.');
} else {
print(result);
}
}
LoginReqDto
class LoginReqDto {
final String? email;
final String? password;
LoginReqDto(this.email, this.password);
Map<String, dynamic> toJson() => {
"email": email,
"password": password,
};
}
UserRepository
Future<String> login(String email, String password) async {
LoginReqDto dto = LoginReqDto(email, password);
try {
await _userProvider.login(dto);
return "success";
} on FirebaseAuthException catch (e) {
return e.code;
}
}
UserProvider
Future<UserCredential> login(LoginReqDto dto) async =>
await auth.signInWithEmailAndPassword(
email: dto.email.toString(), password: dto.password.toString());
Git Commit
https://github.com/mugon-dev/flutter_firebase_blog/commit/d5a51d681816c3759436585345cbf2d4fc39dab4
728x90
'Project > flutter_firebase_blog' 카테고리의 다른 글
7. user info page 구현 (0) | 2021.07.26 |
---|---|
6. firebase auth, firebase cloud storage를 활용하여 google login 구현 (0) | 2021.07.26 |
4. firebase auth, firebase cloud storage를 활용하여 email 회원가입 구현 (0) | 2021.07.24 |
3. firebase auth 사용하여 로그인 상태에 따른 페이지 이동 (0) | 2021.07.24 |
2. firebase setting (0) | 2021.07.21 |