Skip to content

Commit

Permalink
Feat(user): fb 로그인 함수 수정
Browse files Browse the repository at this point in the history
- 로직은 firebase.js 파일 내에서 처리하도록 수정

ref: #67
  • Loading branch information
hwna00 committed Sep 20, 2023
1 parent 45cf198 commit 08d25d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
15 changes: 12 additions & 3 deletions packages/apps/user/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,21 @@ const fbSignUp = data => {
});
};

const logIn = (email, password) => {
return signInWithEmailAndPassword(auth, email, password);
const fbLogIn = data => {
const { email, data } = data;

//TODO: DB에 해당 email과 같은 메일이 존재하는지 확인. 존재한다면 해당 아이디가 이미 존재한다는 경고메시지 전송

signInWithEmailAndPassword(auth, email, password)
.then(userCredential => {
const { email } = userCredential.user;
//TODO: email을 가지는 user 정보를 DB에서 가져온다.
})
.catch();
};

const googleLogin = () => {
return signInWithPopup(auth, provider);
};

export { auth, fbSignUp, logIn, googleLogin, provider, storage };
export { auth, fbSignUp, fbLogIn, googleLogin, provider, storage };
21 changes: 10 additions & 11 deletions packages/apps/user/src/views/Auth/LogIn/LogIn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react';

import { useNavigate , Link as ReactRouterLink } from 'react-router-dom';
import { useNavigate, Link as ReactRouterLink } from 'react-router-dom';
import { FaUserAlt, FaLock } from 'react-icons/fa';
import {
AiFillGithub,
Expand All @@ -25,13 +25,20 @@ import {
Icon,
} from '@chakra-ui/react';

import { logIn, googleLogin, auth, provider } from '../../../../firebase';
import {
logIn,
googleLogin,
auth,
provider,
fbLogIn,
} from '../../../../firebase';

function LogIn() {
const [showPassword, setShowPassword] = useState(false);
const handleShowClick = useCallback(() => {
setShowPassword(!showPassword);
}, [showPassword]);

const navigate = useNavigate();
const {
register,
Expand All @@ -40,15 +47,7 @@ function LogIn() {
} = useForm();

const onSubmit = function (data) {
const { email, password } = data;
logIn(email, password)
.then(() => {
navigate('/');
})
.catch(error => {
console.log(error);
navigate('/error');
});
fbLogIn(data);
};

const googleClick = useCallback(() => {
Expand Down

0 comments on commit 08d25d8

Please sign in to comment.