TIL.231208 팀프로젝트2

안은지·2023년 12월 11일
0

📌아웃소싱 프로젝트 끝

  • WBS & Tasks
    • 로그인/회원가입, 이용중인 유저정보 관리(firebase-authentication)

🖥️firebase Authentication을 이용한 로그인

createUserWithEmailAndPassword 함수를 이용한 방법과 거의 동일하다(회원가입). 다만 이번에는 signInWithEmailAndPassword 함수를 이용해서 이메일과 패스워드를 입력해서 로그인 할 수 있다.

사용방법은 다음과 같다.

signInWithEmailAndPassword(auth객체, 이메일, 패스워드)

firebase공식문서에 친절하게 사용방법이 적혀있다👍

⬇️로그인코드

  const login = async (e) => {
    e.preventDefault();
    try {
      const userCredential = await signInWithEmailAndPassword(AUTH, email, password);
      setEmail('');
      setPassword('');
      dispatch(modalClose());
      navigate('/');
    } catch (error) {
      const errorCode = error.code;
      const errorMessage = error.message;
      console.log('error with LogIn', errorCode, errorMessage);
      alert('등록되지 않은 회원이거나 유효하지 않은 이메일입니다.');
    }
  };

//하단 코드 생략


Firebase 콘솔에서 확인해보면, 정상적으로 유저 정보가 저장된 것을 확인할 수 있다.

☑️마치며

회원가입이랑 별다른 차이점이 없어 약간의 수정으로 더 빠르게 완성할 수 있었다(구글로그인과, 유효성 검사 및 토글링 까지 끄읕)
👍

0개의 댓글