728x90
반응형

signOut 을 firebase 파일에서 불러올수가 없어 어떡하지 하는 찰나에
그냥 직접 가져오면 안되나 싶어서 해보니 결국 해결했다
import { signOut } from "firebase/auth";
export const NavBar = () => {
const authState = useSelector((state) => state.authSlice);
const dispatch = useDispatch();
console.log(authState.isLogin);
// const dispatch = useDispatch();
// const isLogin = useSelector((state) => state.authSlice.isLogin);
const logoutHandler = async () => {
await signOut(auth);
swal("로그아웃", "로그아웃 되었습니다.", "success");
dispatch(changeLoginStatus(false));
console.log(authState.isLogin);
};
하지만 다시 오류 발생...!

로그인이 성공해도 실패 alert가 같이 떠버리는 상황이 발생했다

콘솔창을보면 41번째 줄인 consol.log(안된다니까요) catch 부분이 계속 뜨는중 결국 튜터님을 찾아갔다
오류 해결
const loginHandler = async (e) => {
e.preventDefault();
try {
const userCredential = await signInWithEmailAndPassword(
auth,
loginEmail,
loginPassword
);
setLoginEmail("");
setLoginPassword("");
dispatch(changeLoginStatus(true));
await swal("로그인 완료 🏕️", "어서오세요!", "success");
} catch (error) {
const errorCode = error.code;
const errorMessage = error.message;
swal(
"Oops...",
"등록되지 않은 회원이거나 유효하지 않은 이메일입니다.",
"error"
);
console.log("error with Login", errorCode, errorMessage);
}
};
개발자도구 페이지에서 네트워크 체크도 해보고 로직 체크도 해보았지만 원인을 알수가없었다
결국 하나하나 주석처리하며 찾다보니 발견!
문제는 로그인 핸들러에 setModalOpen 함수였다.훅도 아니고 함수로 되어있었는데
props를 받아오지도 않았고 그냥 아무것도 정의 되지않았던 함수였던것
그래서 동작에는 문제가 없었지만 error는 모든 종류의 error를 잡았기에 일단 console.log가 작동하였던겄이였다
error를 잡을때에는 콘솔로그에도 에러코드를 정확히 입력해줘야겠다
console.log("error with Login", errorCode, errorMessage);
728x90
반응형
'Today I Learned (TIL)' 카테고리의 다른 글
2023년 마지막 TIL (0) | 2023.12.31 |
---|---|
TIL 23.12.30 심화프로젝트 5일차 (1) | 2023.12.30 |
TIL 23.12.28 심화프로젝트 3일차 (0) | 2023.12.28 |
23.12.27 심화프로젝트 2일차 (0) | 2023.12.27 |
TIL 심화 프로젝트 시작 23.12.26 (0) | 2023.12.26 |