로그인 버튼 함수

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

 

email, password, username 회원가입, 로그인, 로그아웃 구현 및 클라우드 저장 · mugon-dev/flutter_firebase_blo

Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files email, password, username 회원가입, 로그인, 로그아웃 구현 및 클라우드 저장 Loading branch informati

github.com

 

728x90

회원가입 버튼 함수

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

 

email, password, username 회원가입, 로그인, 로그아웃 구현 및 클라우드 저장 · mugon-dev/flutter_firebase_blo

Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files email, password, username 회원가입, 로그인, 로그아웃 구현 및 클라우드 저장 Loading branch informati

github.com

 

728x90

+ Recent posts