Skip to content

Commit 14df1e9

Browse files
authored
Merge pull request #168 from StepUpper/develop
로그인, 회원가입 리팩토링과 배포 시 로그 제거
2 parents 3873294 + 15a09a6 commit 14df1e9

10 files changed

Lines changed: 113 additions & 70 deletions

File tree

frontend/src/apis/firebase/auth.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
doc,
1313
getDoc,
1414
getDocs,
15+
query,
1516
setDoc,
1617
updateDoc,
18+
where,
1719
} from "firebase/firestore";
1820

1921
interface UserTypeforSignup {
@@ -69,25 +71,24 @@ const updateUserData = async (key: string, value: string | number) => {
6971

7072
const signUpWithCredential = async (user: UserTypeforSignup & TUser) => {
7173
const { email, password, ...rest } = user;
72-
await createUserWithEmailAndPassword(auth, email, password)
73-
.then((credential) => {
74+
await createUserWithEmailAndPassword(auth, email, password).then(
75+
(credential) => {
7476
setDoc(doc(db, "users", credential.user.uid), {
7577
...rest,
78+
email: email,
7679
imgUrl: "",
7780
sizeType: null,
7881
sneakerSize: 0,
7982
});
80-
})
81-
.catch((e) => alert(e));
83+
}
84+
);
8285
};
8386

8487
const signInWithCredential = async (user: {
8588
email: string;
8689
password: string;
8790
}) => {
88-
await signInWithEmailAndPassword(auth, user.email, user.password)
89-
.then()
90-
.catch((e) => alert(e.message));
91+
await signInWithEmailAndPassword(auth, user.email, user.password);
9192
};
9293

9394
const signInWithGoogle = async () => {
@@ -96,6 +97,7 @@ const signInWithGoogle = async () => {
9697
const isNew = await signInWithPopup(auth, provider)
9798
.then((credential) => {
9899
setDoc(doc(db, "users", credential.user.uid), {
100+
email: credential.user.email,
99101
username: credential.user.displayName,
100102
gender: null,
101103
birthDate: "",
@@ -120,11 +122,20 @@ const logOut = async () => {
120122
.catch((e) => alert(e.message));
121123
};
122124

125+
const availableAccount = async (email: string) => {
126+
const docRef = collection(db, "users");
127+
const q = query(docRef, where("email", "==", email));
128+
const querySnapshot = await getDocs(q);
129+
130+
return querySnapshot.empty;
131+
};
132+
123133
export {
124134
getUserData,
125135
updateUserData,
126136
signUpWithCredential,
127137
signInWithCredential,
128138
signInWithGoogle,
129139
logOut,
140+
availableAccount,
130141
};

frontend/src/components/Chat/ChatLoading.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const ChatLoading = () => {
22
return (
3-
<div className="fixed inset-0 z-50 flex items-center justify-center bg-gray-800 bg-opacity-15">
3+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-gray-800/15">
44
<div className="flex space-x-6">
5-
<div className="h-3 w-3 animate-pulse rounded-full bg-gray-400" />
6-
<div className="animation-delay-200 h-3 w-3 animate-pulse rounded-full bg-gray-500" />
7-
<div className="animation-delay-400 h-3 w-3 animate-pulse rounded-full bg-gray-600" />
5+
<div className="size-3 animate-pulse rounded-full bg-gray-400" />
6+
<div className="delay-200 size-3 animate-pulse rounded-full bg-gray-500" />
7+
<div className="delay-400 size-3 animate-pulse rounded-full bg-gray-600" />
88
</div>
99
</div>
1010
);

frontend/src/components/common/html/DropDown.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const DropDown = forwardRef<DropDownRef, DropDownProps>((props, ref) => {
4141
setIsOpen(false);
4242
if (onChange) {
4343
onChange(value);
44-
console.log(value);
4544
}
4645
};
4746

frontend/src/components/common/html/Input.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { ComponentPropsWithoutRef, forwardRef } from "react";
22
import { twMerge } from "tailwind-merge";
33

4-
type InputProps = ComponentPropsWithoutRef<"input">;
4+
type InputProps = ComponentPropsWithoutRef<"input"> & { isErrored?: boolean };
55

66
const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
77
const { className, ...rest } = props;
88
return (
99
<>
1010
<input
11-
className={twMerge("border text-body2", className)}
11+
className={twMerge(
12+
"border text-body2 focus:border-grey-600",
13+
className,
14+
rest.isErrored && "border-red-300 text-red"
15+
)}
1216
ref={ref}
1317
{...rest}
14-
></input>
18+
/>
1519
</>
1620
);
1721
});

frontend/src/components/login/Login.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const Login = () => {
4545
[name]: value,
4646
});
4747

48-
if (name === "email") setEmailError("");
49-
if (name === "password") setPasswordError("");
48+
setEmailError("");
49+
setPasswordError("");
5050
};
5151

5252
const submitHandle = async (e: React.FormEvent) => {
@@ -87,7 +87,15 @@ const Login = () => {
8787

8888
//값 확인용
8989
if (isLoginValid) {
90-
await signInWithCredential(loginData);
90+
await signInWithCredential(loginData)
91+
.then(() => {
92+
closeAll();
93+
navigate("/");
94+
})
95+
.catch(() => {
96+
setEmailError("이메일을 확인해주세요.");
97+
setPasswordError("비밀번호를 확인해주세요.");
98+
});
9199
// zustand로 관리하는 user가 업데이트가 바로 안이루어져서,
92100
// 임시 방편으로 updateUserInfo 가 userData를 반환하게끔 하고
93101
// 반환값을 사용하도록 하자
@@ -96,8 +104,6 @@ const Login = () => {
96104
uid: string;
97105
username: string;
98106
};
99-
closeAll();
100-
navigate("/");
101107

102108
// 여기서 맞춤상품 api 호출 처리
103109
try {
@@ -137,6 +143,7 @@ const Login = () => {
137143
<InputField title="아이디" error={emailError}>
138144
<Input
139145
ref={emailRef}
146+
isErrored={!!emailError}
140147
type="email"
141148
name="email"
142149
placeholder="이메일을 입력해주세요"
@@ -150,6 +157,7 @@ const Login = () => {
150157
<InputField title="비밀번호" error={passwordError}>
151158
<Input
152159
ref={passwordRef}
160+
isErrored={!!passwordError}
153161
type="password"
154162
name="password"
155163
placeholder="비밀번호를 입력해주세요"

frontend/src/components/login/LoginBottomSheet.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
22
import { useLocation } from "react-router-dom";
33
import BottomSheet from "@common/BottomSheet";
44
import Login from "@components/login/Login";
5-
import SignUp from "@components/signup/SignUp";
5+
import SignUp from "@components/signUp/SignUp";
66

77
const LoginBottomSheet = () => {
88
const location = useLocation();

frontend/src/components/signup/SignUp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SignUpRequired from "./SignUpRequired";
2-
import SignUpAdditional from "./SignUpAdditional";
1+
import SignUpRequired from "@components/signUp/SignUpRequired";
2+
import SignUpAdditional from "@components/signUp/SignUpAdditional";
33
import userStore from "@store/auth.store.ts";
44
import { redirect } from "react-router-dom";
55

0 commit comments

Comments
 (0)