-
Notifications
You must be signed in to change notification settings - Fork 18
[나지원] sprint11 #133
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
Merged
GANGYIKIM
merged 8 commits into
codeit-bootcamp-frontend:Next-나지원
from
najitwo:Next-나지원-sprint11
Nov 12, 2024
The head ref may contain hidden characters: "Next-\uB098\uC9C0\uC6D0-sprint11"
Merged
[나지원] sprint11 #133
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fb8b522
feat: add login page
najitwo 4a2eeaf
feat: add signup page
najitwo 552d437
feat: add home page
najitwo e08e084
feat: replace login button with pada logo if access token is present
najitwo ed2d884
feat: refresh access token on 401 response status
najitwo f3a3f27
feat: implement page redirection based on access token presence
najitwo 8e483c1
refactor: extract SocialLogin component for better readability
najitwo d3ad96d
feat: implement comment editing
najitwo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| .authForm { | ||
| max-width: 400px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| } | ||
|
|
||
| .input { | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .authForm label { | ||
| font-size: 0.875rem; | ||
| line-height: 1.5rem; | ||
| } | ||
|
|
||
| .btnEye { | ||
| position: absolute; | ||
| width: 24px; | ||
| height: 24px; | ||
| top: 16px; | ||
| right: 16px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .button { | ||
| padding: 12px 145px; | ||
| border-radius: 40px; | ||
| font-size: 1.25rem; | ||
| line-height: 2rem; | ||
| cursor: pointer; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .button.active { | ||
| background-color: var(--blue); | ||
| } | ||
|
|
||
| .validationFocus { | ||
| outline: 1px solid var(--red); | ||
| } | ||
|
|
||
| .validationMessage { | ||
| display: none; | ||
| font-size: 0.875rem; | ||
| font-weight: 600; | ||
| line-height: 1.5rem; | ||
| color: var(--red); | ||
| padding-left: 16px; | ||
| margin-top: 8px; | ||
| } | ||
|
|
||
| .authLink { | ||
| font-size: 0.875rem; | ||
| font-weight: 500; | ||
| line-height: 1.5rem; | ||
| text-align: center; | ||
| color: var(--gary800); | ||
| } | ||
|
|
||
| .authLink > a { | ||
| color: var(--blue); | ||
| text-decoration: underline; | ||
| padding-left: 4px; | ||
| } | ||
|
|
||
| @media screen and (min-width: 768px) { | ||
| .authForm { | ||
| max-width: 100%; | ||
| width: 640px; | ||
| gap: 24px; | ||
| } | ||
|
|
||
| .input { | ||
| gap: 16px; | ||
| } | ||
|
|
||
| .authForm label { | ||
| font-size: 1.125rem; | ||
| line-height: 1.625rem; | ||
| } | ||
|
|
||
| .authForm .authInput { | ||
| padding: 16px 24px; | ||
| } | ||
|
|
||
| .button { | ||
| padding: 16px 124px; | ||
| margin-bottom: 0; | ||
| } | ||
|
|
||
| .authForm > .otherAccount { | ||
| margin-bottom: 0; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { useState } from "react"; | ||
| import Link from "next/link"; | ||
| import Image from "next/image"; | ||
| import { useRouter } from "next/router"; | ||
| import { useForm } from "react-hook-form"; | ||
| import useAuth from "@/hooks/useAuth"; | ||
| import FormInput from "../ui/FormInput"; | ||
| import SocialLogin from "./SocialLogin"; | ||
| import Button from "../ui/Button"; | ||
| import styles from "./AuthForm.module.css"; | ||
| import hideIcon from "@/public/btn_hide.svg"; | ||
| import showIcon from "@/public/btn_show.svg"; | ||
|
|
||
| interface FormValues extends Record<string, string> { | ||
| email: string; | ||
| password: string; | ||
| } | ||
|
|
||
| const LoginForm = () => { | ||
| const [showPassword, setShowPassword] = useState(false); | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isValid }, | ||
| setError, | ||
| } = useForm<FormValues>({ mode: "onChange" }); | ||
| const router = useRouter(); | ||
| const { login } = useAuth(); | ||
|
|
||
| const onSubmit = async (data: FormValues) => { | ||
| try { | ||
| await login(data); | ||
| router.push("/"); | ||
| } catch (err: unknown) { | ||
| if (err instanceof Error) { | ||
| if (err.message === "존재하지 않는 이메일입니다.") { | ||
| setError("email", { type: "manual", message: err.message }); | ||
| } | ||
| if (err.message === "비밀번호가 일치하지 않습니다.") { | ||
| setError("password", { type: "manual", message: err.message }); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const togglePasswordVisibility = () => { | ||
| setShowPassword(!showPassword); | ||
| }; | ||
|
|
||
| return ( | ||
| <form className={styles.authForm} onSubmit={handleSubmit(onSubmit)}> | ||
| <FormInput | ||
| className={styles.input} | ||
| type="text" | ||
| name="email" | ||
| label="이메일" | ||
| placeholder="이메일을 입력해주세요" | ||
| register={register} | ||
| required="이메일을 입력해주세요." | ||
| pattern={{ | ||
| value: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, | ||
| message: "잘못된 이메일 형식입니다.", | ||
| }} | ||
| error={errors.email} | ||
| /> | ||
| <FormInput | ||
| className={styles.input} | ||
| type={showPassword ? "text" : "password"} | ||
| name="password" | ||
| label="비밀번호" | ||
| placeholder="비밀번호를 입력해주세요" | ||
| register={register} | ||
| required="비밀번호를 입력해주세요." | ||
| minLength={{ | ||
| value: 8, | ||
| message: "비밀번호를 8자 이상 입력해주세요.", | ||
| }} | ||
| error={errors.password} | ||
| > | ||
| <Image | ||
| src={showPassword ? showIcon : hideIcon} | ||
| className={styles.btnEye} | ||
| onClick={togglePasswordVisibility} | ||
| alt="비밀번호 표시" | ||
| /> | ||
| </FormInput> | ||
| <Button className={styles.button} type="submit" disabled={!isValid}> | ||
| 로그인 | ||
| </Button> | ||
| <SocialLogin /> | ||
| <span className={styles.authLink}> | ||
| 판다마켓이 처음이신가요? | ||
| <Link href="/signup">회원가입</Link> | ||
| </span> | ||
| </form> | ||
| ); | ||
| }; | ||
|
|
||
| export default LoginForm; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { useState, useEffect } from "react"; | ||
| import Link from "next/link"; | ||
| import Image from "next/image"; | ||
| import { useRouter } from "next/router"; | ||
| import { useForm } from "react-hook-form"; | ||
| import useAuth from "@/hooks/useAuth"; | ||
| import FormInput from "../ui/FormInput"; | ||
| import SocialLogin from "./SocialLogin"; | ||
| import Button from "../ui/Button"; | ||
| import styles from "./AuthForm.module.css"; | ||
| import hideIcon from "@/public/btn_hide.svg"; | ||
| import showIcon from "@/public/btn_show.svg"; | ||
|
|
||
| interface FormValues extends Record<string, string> { | ||
| email: string; | ||
| nickname: string; | ||
| password: string; | ||
| passwordConfirmation: string; | ||
| } | ||
|
|
||
| const LoginForm = () => { | ||
| const [showPassword, setShowPassword] = useState(false); | ||
| const [showPasswordConfirmation, setShowPasswordConfirmation] = | ||
| useState(false); | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isValid }, | ||
| watch, | ||
| setError, | ||
| trigger, | ||
| } = useForm<FormValues>({ mode: "onChange" }); | ||
| const router = useRouter(); | ||
| const { signup } = useAuth(); | ||
| const watchedPassword = watch("password"); | ||
|
|
||
| const onSubmit = async (data: FormValues) => { | ||
| try { | ||
| await signup(data); | ||
| router.push("/login"); | ||
| } catch (err: unknown) { | ||
| if (err instanceof Error) { | ||
| if (err.message === "이미 사용중인 이메일입니다.") { | ||
| setError("email", { type: "manual", message: err.message }); | ||
| } | ||
| if (err.message === "이미 사용중인 닉네임입니다.") { | ||
| setError("nickname", { type: "manual", message: err.message }); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const togglePasswordVisibility = () => setShowPassword(!showPassword); | ||
| const togglePasswordConfirmationVisibility = () => | ||
| setShowPasswordConfirmation(!showPasswordConfirmation); | ||
|
|
||
| useEffect(() => { | ||
| if (watchedPassword) { | ||
| trigger("passwordConfirmation"); | ||
| } | ||
| }, [watchedPassword, trigger]); | ||
|
|
||
| return ( | ||
| <form className={styles.authForm} onSubmit={handleSubmit(onSubmit)}> | ||
| <FormInput | ||
| className={styles.input} | ||
| type="text" | ||
| name="email" | ||
| label="이메일" | ||
| placeholder="이메일을 입력해주세요" | ||
| register={register} | ||
| required="이메일을 입력해주세요" | ||
| pattern={{ | ||
| value: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, | ||
| message: "잘못된 이메일 형식입니다.", | ||
| }} | ||
| error={errors.email} | ||
| /> | ||
| <FormInput | ||
| className={styles.input} | ||
| type="text" | ||
| name="nickname" | ||
| label="닉네임" | ||
| placeholder="닉네임을 입력해주세요" | ||
| register={register} | ||
| required="닉네임을 입력해주세요" | ||
| error={errors.nickname} | ||
| /> | ||
| <FormInput | ||
| className={styles.input} | ||
| type={showPassword ? "text" : "password"} | ||
| name="password" | ||
| label="비밀번호" | ||
| placeholder="비밀번호를 입력해주세요" | ||
| register={register} | ||
| required="비밀번호를 입력해주세요." | ||
| minLength={{ | ||
| value: 8, | ||
| message: "비밀번호를 8자 이상 입력해주세요.", | ||
| }} | ||
| error={errors.password} | ||
| > | ||
| <Image | ||
| src={showPassword ? showIcon : hideIcon} | ||
| className={styles.btnEye} | ||
| onClick={togglePasswordVisibility} | ||
| alt="비밀번호 표시" | ||
| /> | ||
| </FormInput> | ||
| <FormInput | ||
| className={styles.input} | ||
| type={showPasswordConfirmation ? "text" : "password"} | ||
| name="passwordConfirmation" | ||
| label="비밀번호 확인" | ||
| placeholder="비밀번호를 다시 한 번 입력해주세요" | ||
| register={register} | ||
| validate={{ | ||
| matchesPassword: (value) => | ||
| value === watchedPassword || "비밀번호가 일치하지 않습니다.", | ||
| required: (value) => value !== "" || "비밀번호 확인을 입력해주세요.", | ||
| }} | ||
| error={errors.passwordConfirmation} | ||
| > | ||
| <Image | ||
| src={showPasswordConfirmation ? showIcon : hideIcon} | ||
| className={styles.btnEye} | ||
| onClick={togglePasswordConfirmationVisibility} | ||
| alt="비밀번호 표시" | ||
| /> | ||
| </FormInput> | ||
| <Button className={styles.button} type="submit" disabled={!isValid}> | ||
| 회원가입 | ||
| </Button> | ||
| <SocialLogin /> | ||
| <span className={styles.authLink}> | ||
| 이미 회원이신가요? | ||
| <Link href="/login">로그인</Link> | ||
| </span> | ||
| </form> | ||
| ); | ||
| }; | ||
|
|
||
| export default LoginForm; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P2:
정규 표현식이 로그인, 회원가입에서 공용으로 쓰이니 따로 객체에 저장해두시고 같이 쓰시면 더 좋을 것 같습니다.
에러메시지도 여러 페이지에서 반복적으로 사용된다면 동일합니다~