회원가입 버튼 함수
UserController.to.join(_username.text.trim(), _email.text.trim(), _password.text.trim());
UserController
Future<void> join(String username, String email, String password) async {
String result = await _userRepository.join(username, 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);
}
}
JoinReqDto
class JoinReqDto {
final String? username;
final String? email;
final String? password;
JoinReqDto(this.username, this.email, this.password);
Map<String, dynamic> toJson() => {
"username": username,
"email": email,
"password": password,
};
}
UserRepository
Future<String> join(String username, String email, String password) async {
JoinReqDto dto = JoinReqDto(username, email, password);
try {
UserCredential userCredential = await _userProvider.join(dto);
UserModel _newUser = UserModel(
uid: userCredential.user!.uid,
email: email,
name: username,
photoUrl: "photoUrl",
);
await _userProvider.joinDetail(_newUser);
return "success";
} on FirebaseAuthException catch (e) {
return e.code;
}
}
UserProvider
// firebase auth 등록
Future<UserCredential> join(JoinReqDto dto) async =>
await auth.createUserWithEmailAndPassword(
email: dto.email.toString(), password: dto.password.toString());
// firebase storage 등록
Future<void> joinDetail(UserModel user) async =>
await firebaseFirestore.doc('/users/${user.uid}').set(user.toJson());
Git Commit
https://github.com/mugon-dev/flutter_firebase_blog/commit/d5a51d681816c3759436585345cbf2d4fc39dab4
'Project > flutter_firebase_blog' 카테고리의 다른 글
6. firebase auth, firebase cloud storage를 활용하여 google login 구현 (0) | 2021.07.26 |
---|---|
5. firebase auth, firebase cloud storage를 활용하여 email, password 로그인 구현 (0) | 2021.07.24 |
3. firebase auth 사용하여 로그인 상태에 따른 페이지 이동 (0) | 2021.07.24 |
2. firebase setting (0) | 2021.07.21 |
1. 프로젝트 구조 설계 (0) | 2021.07.21 |