-
Notifications
You must be signed in to change notification settings - Fork 37
[김승석] Sprint11 #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "Next-\uAE40\uC2B9\uC11D-sprint11"
[김승석] Sprint11 #319
Changes from all commits
592a3d9
c94f749
7c3cfc5
498ba56
32ae842
8d3017f
2f83b8f
87d6588
e8cb077
ecc2dbb
0011b09
863aca2
406d403
3871bf7
fe6b0f8
ae625b6
a63a913
9fe291d
5d3c518
59e5603
2777c37
eb288f0
9ba593a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| } | ||
| .header .my { | ||
| margin-left: auto; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| @media (max-width: 744px) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import axios from "axios"; | ||
|
|
||
| const Instance = axios.create({ | ||
| baseURL: "https://panda-market-api.vercel.app", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. baseURL같은건 env로 관리하는게 더 좋아보이네요 |
||
| }); | ||
|
|
||
| export default Instance; | ||
| export { axios }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import FormInput from "@/components/form/form-input"; | ||
| import styles from "./../signup/signup.module.css"; | ||
| import { useEffect, useState } from "react"; | ||
| import Link from "next/link"; | ||
| import Instance, { axios } from "@/lib/axios"; | ||
| import { isAxiosError } from "axios"; | ||
| import { useRouter } from "next/router"; | ||
|
|
||
| export default function Page() { | ||
| const router = useRouter(); | ||
| const [loginValue, setLoginValue] = useState({ | ||
| email: "", | ||
| password: "", | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const accessToken = localStorage.getItem("accessToken"); | ||
| if (accessToken) { | ||
| router.push("/"); | ||
| } | ||
| }, [router]); | ||
|
|
||
| const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const { name, value } = e.target; | ||
| setLoginValue((prev) => ({ | ||
| ...prev, | ||
| [name]: value, | ||
| })); | ||
| }; | ||
|
|
||
| const onSignInSubmit: React.FormEventHandler<HTMLFormElement> = async (e) => { | ||
| e.preventDefault(); | ||
|
|
||
| const { email, password } = loginValue; | ||
|
|
||
| if (!email || !password) { | ||
| alert("모든 필드를 채워주세요."); | ||
| return; | ||
| } | ||
| if (!/\S+@\S+\.\S+/.test(email)) { | ||
| alert("유효한 이메일 주소를 입력해주세요."); | ||
| return; | ||
| } | ||
| if (password.length < 8) { | ||
| alert("비밀번호는 최소 8자 이상이어야 합니다."); | ||
| return; | ||
| } | ||
|
Comment on lines
+36
to
+47
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validation로직은 submit함수에서 따로 추출하는게 더 좋아보이네요 |
||
|
|
||
| try { | ||
| const response = await Instance.post("/auth/signIn", { | ||
| email, | ||
| password, | ||
| }); | ||
| alert("로그인이 성공적으로 완료되었습니다!"); | ||
|
|
||
| // 서버로부터 받은 데이터 추출 | ||
| const { user, accessToken, refreshToken } = response.data; | ||
|
|
||
| // 로컬스토리지에 토큰과 사용자 데이터 저장 | ||
| localStorage.setItem("accessToken", accessToken); | ||
| localStorage.setItem("refreshToken", refreshToken); | ||
| localStorage.setItem("user", JSON.stringify(user)); // 객체는 JSON 문자열로 변환 | ||
|
|
||
| setLoginValue({ | ||
| email: "", | ||
| password: "", | ||
| }); | ||
| router.push("/"); | ||
| } catch (error) { | ||
| if (isAxiosError(error) && error.response) { | ||
| console.error("서버 응답 상태 코드:", error.response.status); | ||
| console.error("서버 응답 데이터:", error.response.data); | ||
| alert(error.response.data.message || "로그인에 실패했습니다."); | ||
| } else { | ||
| console.error("알 수 없는 오류:", error); | ||
| alert("로그인 중 문제가 발생했습니다. 다시 시도해주세요."); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={styles.login_wrap}> | ||
| <div className={styles.logo}> | ||
| <Link href="/"> | ||
| <img src="/assets/img/logo.svg" alt="로고" /> | ||
| </Link> | ||
| </div> | ||
| <form onSubmit={onSignInSubmit}> | ||
| <ul className={styles.login_list}> | ||
| <li> | ||
| <div className={styles.title}>이메일</div> | ||
| <div className={styles.content}> | ||
| <FormInput | ||
| type="email" | ||
| name="email" | ||
| placeholder="이메일을 입력해주세요" | ||
| onChange={onChange} | ||
| value={loginValue.email} | ||
| /> | ||
| </div> | ||
| </li> | ||
| <li> | ||
| <div className={styles.title}>비밀번호</div> | ||
| <div className={styles.content}> | ||
| <FormInput | ||
| type="password" | ||
| name="password" | ||
| placeholder="비밀번호를 입력해주세요" | ||
| onChange={onChange} | ||
| value={loginValue.password} | ||
| /> | ||
| </div> | ||
| </li> | ||
| <li> | ||
| <button className="btn round block large" disabled={false}> | ||
| 로그인 | ||
| </button> | ||
| </li> | ||
| <li> | ||
| <div className={styles.sns}> | ||
| <h3>간편 로그인하기</h3> | ||
| <ul> | ||
| <li> | ||
| <Link href=""> | ||
| <img | ||
| src="/assets/img/icon_google.svg" | ||
| alt="구글 간편로그인" | ||
| /> | ||
| </Link> | ||
| </li> | ||
| <li> | ||
| <Link href=""> | ||
| <img | ||
| src="/assets/img/icon_kakao.svg" | ||
| alt="카카오 간편로그인" | ||
| /> | ||
| </Link> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </li> | ||
| <li> | ||
| <div className={styles.link}> | ||
| <p> | ||
| 판다마켓이 처음이신가요? <Link href="/signup">회원가입</Link> | ||
| </p> | ||
| </div> | ||
| </li> | ||
| </ul> | ||
| </form> | ||
| </div> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런식으로 early return기법을 사용해보는건 어떨까요