Skip to content

Commit

Permalink
Fix: 13주차 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
juncastle97 committed Jan 24, 2024
1 parent c1bc480 commit 7d48ade
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
File renamed without changes.
10 changes: 4 additions & 6 deletions lib/loginApi.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import axios from "axios";

const baseURL = "https://bootcamp-api.codeit.kr/api";
import instance from "./axios";

export async function signIn(email, password, setError) {
try {
const res = await axios.post(`${baseURL}/sign-in`, {
const res = await instance('/sign-in', {
email,
password,
});
Expand All @@ -25,7 +23,7 @@ export async function signIn(email, password, setError) {

export async function signUp(email, password) {
try {
const res = await axios.post(`${baseURL}/sign-up`, { email, password });
const res = await instance('/sign-up', { email, password });
if (res.status === 200) {
const accessToken = res.config.data;
localStorage.setItem("signUpAccessToken", accessToken);
Expand All @@ -38,7 +36,7 @@ export async function signUp(email, password) {

export async function checkEmail(email, setError) {
try {
const res = await axios.post(`${baseURL}/check-email`, { email });
const res = await instance('/check-email', { email });
if (res?.status === 200) {
return true;
}
Expand Down
16 changes: 11 additions & 5 deletions pages/signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { errorMessages, emailRegex, passwordRegex } from "../utils/regexp";
import { signIn } from "../lib/loginApi";
import Image from "next/image";
import styles from "../styles/Sign.module.css";
import LogoTitle from "../components/signPage/LogoTitle";
import LogoTitle from "../components/elements/LogoTitle";
import SubmitButton from "../components/elements/SubmitButton";
import SnsLogin from "../components/elements/snsLogin";

Expand Down Expand Up @@ -44,7 +44,11 @@ function Signin() {
})}
placeholder="이메일을 입력해 주세요."
/>
<span className={styles.ErrorMessage}>{errors?.email?.message}</span>
{!!errors.email && (
<span className={styles.ErrorMessage}>
{errors?.email?.message}
</span>
)}
</div>
<div className={styles.GapWrapper}>
<label htmlFor="password" className={styles.Label}>
Expand Down Expand Up @@ -85,9 +89,11 @@ function Signin() {
</div>
</div>
</div>
<span className={styles.ErrorMessage}>
{errors?.password?.message}
</span>
{!!errors.password && (
<span className={styles.ErrorMessage}>
{errors?.password?.message}
</span>
)}
</div>
<div className={styles.subBtn}>
<SubmitButton text={"로그인"} />
Expand Down
29 changes: 13 additions & 16 deletions pages/signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { errorMessages, emailRegex, passwordRegex } from "../utils/regexp";
import { signUp, checkEmail } from "../lib/loginApi";
import Image from "next/image";
import styles from "../styles/Sign.module.css";
import LogoTitle from "../components/signPage/LogoTitle";
import LogoTitle from "../components/elements/LogoTitle";
import SubmitButton from "../components/elements/SubmitButton";
import SnsLogin from "../components/elements/snsLogin";

Expand All @@ -21,18 +21,6 @@ function Signup() {
await checkEmail(watch("email"), setError);
};

const onValid = (data) => {
if (data.password !== data.passwordValid) {
setError(
"passwordValid",
{ message: errorMessages.passwordNotCorrect },
{ shouldFocus: true }
);
} else {
onSubmit();
}
};

const togglePasswordVisibility = () => {
setIsPasswordVisible((prevState) => !prevState);
};
Expand All @@ -42,7 +30,7 @@ function Signup() {

return (
<>
<form className={styles.Container} onSubmit={handleSubmit(onValid)}>
<form className={styles.Container} onSubmit={handleSubmit(onSubmit)}>
<LogoTitle />

<div className={styles.GapWrapper}>
Expand All @@ -62,7 +50,11 @@ function Signup() {
})}
placeholder="이메일을 입력해 주세요."
/>
<span className={styles.ErrorMessage}>{errors?.email?.message}</span>
{!!errors.email && (
<span className={styles.ErrorMessage}>
{errors?.email?.message}
</span>
)}
</div>

<div className={styles.GapWrapper}>
Expand Down Expand Up @@ -124,6 +116,11 @@ function Signup() {
value: passwordRegex,
message: errorMessages.passwordValid,
},
validate: (value, { password }) => {
if (value !== password) {
return errorMessages.passwordNotCorrect;
}
},
})}
type={isPasswordValidVisible ? "text" : "password"}
placeholder="비밀번호를 입력해 주세요."
Expand Down Expand Up @@ -154,7 +151,7 @@ function Signup() {
</div>

<div className={styles.subBtn}>
<SubmitButton text={"로그인"} />
<SubmitButton text={"회원가입"} />
</div>
<SnsLogin />
</form>
Expand Down

0 comments on commit 7d48ade

Please sign in to comment.