Skip to content

Commit 1e54e57

Browse files
authored
Revert "로그인, 회원가입 리팩토링과 배포 시 로그 제거 (#167)"
This reverts commit 025f6bc.
1 parent 025f6bc commit 1e54e57

8 files changed

Lines changed: 64 additions & 104 deletions

File tree

frontend/src/apis/firebase/auth.ts

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

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

7270
const signUpWithCredential = async (user: UserTypeforSignup & TUser) => {
7371
const { email, password, ...rest } = user;
74-
await createUserWithEmailAndPassword(auth, email, password).then(
75-
(credential) => {
72+
await createUserWithEmailAndPassword(auth, email, password)
73+
.then((credential) => {
7674
setDoc(doc(db, "users", credential.user.uid), {
7775
...rest,
78-
email: email,
7976
imgUrl: "",
8077
sizeType: null,
8178
sneakerSize: 0,
8279
});
83-
}
84-
);
80+
})
81+
.catch((e) => alert(e));
8582
};
8683

8784
const signInWithCredential = async (user: {
8885
email: string;
8986
password: string;
9087
}) => {
91-
await signInWithEmailAndPassword(auth, user.email, user.password);
88+
await signInWithEmailAndPassword(auth, user.email, user.password)
89+
.then()
90+
.catch((e) => alert(e.message));
9291
};
9392

9493
const signInWithGoogle = async () => {
@@ -97,7 +96,6 @@ const signInWithGoogle = async () => {
9796
const isNew = await signInWithPopup(auth, provider)
9897
.then((credential) => {
9998
setDoc(doc(db, "users", credential.user.uid), {
100-
email: credential.user.email,
10199
username: credential.user.displayName,
102100
gender: null,
103101
birthDate: "",
@@ -122,20 +120,11 @@ const logOut = async () => {
122120
.catch((e) => alert(e.message));
123121
};
124122

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-
133123
export {
134124
getUserData,
135125
updateUserData,
136126
signUpWithCredential,
137127
signInWithCredential,
138128
signInWithGoogle,
139129
logOut,
140-
availableAccount,
141130
};

frontend/src/components/Chat/ChatLoading.tsx

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

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

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
88
return (
99
<>
1010
<input
11-
className={twMerge(
12-
"border text-body2 focus:border-grey-600",
13-
className,
14-
rest.isErrored && "border-red-300 text-red"
15-
)}
11+
className={twMerge("border text-body2", className)}
1612
ref={ref}
1713
{...rest}
1814
></input>

frontend/src/components/login/Login.tsx

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

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

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

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

109102
// 여기서 맞춤상품 api 호출 처리
110103
try {
@@ -125,6 +118,7 @@ const Login = () => {
125118
});
126119
}
127120
} catch (error) {
121+
console.log(error);
128122
const errorMessage =
129123
"예기치 못한 에러가 발생하였습니다. 다시 시도해주세요.";
130124
if (isLoggedIn) {
@@ -143,7 +137,6 @@ const Login = () => {
143137
<InputField title="아이디" error={emailError}>
144138
<Input
145139
ref={emailRef}
146-
isErrored={emailError}
147140
type="email"
148141
name="email"
149142
placeholder="이메일을 입력해주세요"
@@ -157,7 +150,6 @@ const Login = () => {
157150
<InputField title="비밀번호" error={passwordError}>
158151
<Input
159152
ref={passwordRef}
160-
isErrored={passwordError}
161153
type="password"
162154
name="password"
163155
placeholder="비밀번호를 입력해주세요"

frontend/src/components/signup/SignUpRequired.tsx

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import InputField from "@common/InputField";
33
import Input from "@common/html/Input";
44
import BottomButton from "@common/BottomButton";
55
import DropDown, { DropDownRef } from "@common/html/DropDown";
6-
import {
7-
availableAccount,
8-
signUpWithCredential,
9-
updateUserData,
10-
} from "@apis/firebase/auth";
6+
import { signUpWithCredential, updateUserData } from "@apis/firebase/auth";
117
import { useInput } from "@hooks/useInput";
128
import userStore from "@store/auth.store";
139
import { auth } from "@/firebase";
@@ -43,6 +39,9 @@ const SignUpRequired = () => {
4339
const [userNameRef, focusUserName, handleUserNamePress] =
4440
useFocus<HTMLInputElement>();
4541
const [genderRef, focusGender] = useFocus<DropDownRef>();
42+
const [birthYearRef, focusBirthYear] = useFocus<DropDownRef>();
43+
const [birthMonthRef, focusBirthMonth] = useFocus<DropDownRef>();
44+
const [birthDayRef, focusBirthDay] = useFocus<DropDownRef>();
4645

4746
const genderOptions: { value: string; label: string }[] = [
4847
{ value: "남성", label: "남성" },
@@ -97,69 +96,74 @@ const SignUpRequired = () => {
9796
if (name === "username") setnameError("");
9897
};
9998

100-
const checkValidate = () => {
101-
let isvalid = true;
99+
const submitHandle = (e: React.FormEvent) => {
100+
e.preventDefault();
101+
102102
const validateEmail = (email: string) => {
103103
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
104104
if (!emailRegex.test(email)) {
105105
focusEmail(); // 이메일 필드 자동 포커스
106106
setEmailError("이메일 형식을 확인해주세요");
107+
isSignUpRequiredValid = false;
108+
return false;
109+
} else {
110+
setEmailError("");
111+
return true;
107112
}
108113
};
109114

115+
let isSignUpRequiredValid = true;
116+
110117
if (!signUpRequired.email) {
111118
//아이디 비어있을 때
112-
focusEmail(); // 이메일 필드 자동 포커스
119+
if (isSignUpRequiredValid) focusEmail(); // 이메일 필드 자동 포커스
120+
113121
setEmailError("아이디를 입력하세요");
114-
isvalid = false;
115-
} else if (emailError.length > 0) {
116-
focusEmail();
117-
isvalid = false;
118-
} else validateEmail(signUpRequired.email);
122+
isSignUpRequiredValid = false;
123+
} else if (validateEmail(signUpRequired.email)) {
124+
isSignUpRequiredValid = true;
125+
}
119126

120127
if (!signUpRequired.password) {
121128
//비밀번호 비어있을 때
122-
if (isvalid) focusPassword(); // 비밀번호 필드 자동 포커스
123-
isvalid = false;
129+
if (isSignUpRequiredValid) focusPassword(); // 비밀번호 필드 자동 포커스
130+
124131
setPasswordError("비밀번호를 입력하세요");
132+
isSignUpRequiredValid = false;
125133
}
126134

127135
if (!signUpRequired.username) {
128-
if (isvalid) focusUserName(); // 이름 필드 자동 포커스
129-
isvalid = false;
136+
if (isSignUpRequiredValid) focusUserName(); // 이름 필드 자동 포커스
137+
130138
setnameError("이름을 입력하세요");
139+
isSignUpRequiredValid = false;
131140
}
132141

133142
if (!signUpRequired.gender) {
134-
if (isvalid) focusGender(); // 성별 필드 자동 포커스
135-
isvalid = false;
143+
if (isSignUpRequiredValid) focusGender(); // 성별 필드 자동 포커스
144+
136145
setGenderError("성별을 입력하세요");
146+
isSignUpRequiredValid = false;
137147
}
138148

139149
if (!signUpRequired.birthDate) {
140150
if (!birthYear) {
141-
// focusBirthYear(); // 년도 필드에 포커스
151+
focusBirthYear(); // 년도 필드에 포커스
142152
setBirthDateError("년도를 선택하세요");
153+
isSignUpRequiredValid = false;
143154
} else if (!birthMonth) {
144-
// focusBirthMonth(); // 월 필드에 포커스
155+
focusBirthMonth(); // 월 필드에 포커스
145156
setBirthDateError("월을 선택하세요");
157+
isSignUpRequiredValid = false;
146158
} else if (!birthDay) {
147-
// focusBirthDay(); // 일 필드에 포커스
159+
focusBirthDay(); // 일 필드에 포커스
148160
setBirthDateError("일을 선택하세요");
161+
isSignUpRequiredValid = false;
149162
}
150163
}
151-
};
152164

153-
const submitHandle = (e: React.FormEvent) => {
154-
e.preventDefault();
155-
156-
if (
157-
emailError.length === 0 &&
158-
passwordError.length === 0 &&
159-
genderError.length === 0 &&
160-
birthDateError.length === 0 &&
161-
nameError.length === 0
162-
) {
165+
//값 확인용
166+
if (isSignUpRequiredValid) {
163167
if (user) {
164168
updateUserData("gender", signUpRequired.gender);
165169
updateUserData("birthDate", signUpRequired.birthDate);
@@ -173,15 +177,7 @@ const SignUpRequired = () => {
173177
gender: signUpRequired.gender === "남성" ? "male" : "female",
174178
username: signUpRequired.username,
175179
birthDate: signUpRequired.birthDate,
176-
})
177-
.then(updateUserInfo)
178-
.catch((data) => {
179-
if (data.code === "auth/email-already-in-use")
180-
setEmailError("이미 사용중인 이메일입니다");
181-
else if (data.code === "auth/weak-password") {
182-
setPasswordError("비밀번호는 6자 이상이어야합니다");
183-
}
184-
});
180+
}).then(updateUserInfo);
185181
}
186182
};
187183

@@ -204,19 +200,11 @@ const SignUpRequired = () => {
204200
type="email"
205201
name="email"
206202
placeholder={user?.email || "이메일을 입력해주세요"}
207-
className={`py-[14px h-[48px] w-full rounded-[4px] px-4`}
208-
isErrored={emailError}
203+
className="h-[48px] w-full rounded-[4px] px-4 py-[14px]"
209204
value={user?.email ? "" : signUpRequired.email}
210205
onChange={handleInputChange}
211206
disabled={user?.email ? true : false}
212207
onKeyDown={(e) => handleEmailPress(e, focusPassword)} // 다음 패스워드 포커스
213-
onBlur={async (e) => {
214-
const isAvailable = await availableAccount(e.target.value);
215-
216-
if (!isAvailable) {
217-
setEmailError("이미 사용중인 이메일입니다");
218-
}
219-
}}
220208
/>
221209
</InputField>
222210
{/*패스워드 입력 필드*/}
@@ -225,7 +213,6 @@ const SignUpRequired = () => {
225213
ref={passwordRef}
226214
type="password"
227215
name="password"
228-
isErrored={passwordError}
229216
placeholder={
230217
user?.email
231218
? "소셜 로그인 회원입니다."
@@ -244,7 +231,6 @@ const SignUpRequired = () => {
244231
ref={userNameRef}
245232
type="text"
246233
name="username"
247-
isErrored={nameError}
248234
placeholder={user?.displayName || "이름을 입력해주세요"}
249235
className="h-[48px] w-full rounded-[4px] px-4 py-[14px]"
250236
value={user?.displayName ? "" : signUpRequired.username}
@@ -267,16 +253,18 @@ const SignUpRequired = () => {
267253
<InputField title="생년월일" error={birthDateError}>
268254
<div className="flex w-full justify-between space-x-1">
269255
<DropDown
256+
ref={birthYearRef}
270257
className="h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
271258
menuPlacement="top"
272259
placeholder="년"
273-
options={birthYearOptions.sort((a, b) => b.value - a.value)}
260+
options={birthYearOptions}
274261
onChange={(value) => {
275262
setBirthYear(value);
276263
updateBirthDate(value, birthMonth, birthDay);
277264
}}
278265
/>
279266
<DropDown
267+
ref={birthMonthRef}
280268
className="h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
281269
menuPlacement="top"
282270
placeholder="월"
@@ -287,6 +275,7 @@ const SignUpRequired = () => {
287275
}}
288276
/>
289277
<DropDown
278+
ref={birthDayRef}
290279
className="h-[45px] gap-2 rounded-[6px] border-[#E4E4E7] px-[10px] py-[14px]"
291280
menuPlacement="top"
292281
placeholder="일"
@@ -307,7 +296,7 @@ const SignUpRequired = () => {
307296
</div>
308297
<div className="mt-4 px-5">
309298
{/*회원가입 다음 페이지로 이동 버튼*/}
310-
<BottomButton title="다음" type="submit" onClick={checkValidate} />
299+
<BottomButton title="다음" type="submit" />
311300
</div>
312301
</form>
313302
</>

frontend/src/styles/tailwind.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
html {
99
font-family: "Pretendard Variable", system-ui, sans-serif;
1010
}
11-
input{
12-
outline: none;
13-
}
1411
}
1512

1613
/* Custom CSS */

0 commit comments

Comments
 (0)