-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/CDP-200-LoginMain #59
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d42662d
CDP-201 featโจ (auth): auth main ๋ ์ด์์ ์ปดํฌ๋ํธ ์ถ๊ฐ
leeunduck beae06a
CDP-200 refactor๐จ (auth): auth layout width ๋ฆฌํฉํ ๋ง
leeunduck 8e331f5
CDP-200 refactor๐จ (auth): auth input & button ๋ฐ์ํ ๋ฆฌํฉํ ๋ง
leeunduck c9c98d3
CDP-200 refactor๐จ (auth): auth header gap ๋ฆฌํฉํ ๋ง
leeunduck fde1c37
CDP-202 featโจ (login): login form ์ปดํฌ๋ํธ ์ถ๊ฐ & login ํ์ด์ง ์ปดํฌ๋ํธ ๋ฐฐ์น
leeunduck 7536fad
CDP-202 featโจ (login): ๊ฐํธ ๋ก๊ทธ์ธ ๊ตฌ๋ถ์ ์ถ๊ฐ
leeunduck 53b1841
CDP-203 featโจ (login): auth ํผ ์ํ๊ด๋ฆฌ store ์ถ๊ฐ & login ์ํ ์ ์ฉ
leeunduck 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
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,9 @@ | ||
| import type { AuthCommonProps } from "@/types/auth"; | ||
|
|
||
| export function AuthMain({ children }: AuthCommonProps) { | ||
| return ( | ||
| <main className="w-full" aria-label="์ธ์ฆ ๋ณธ๋ฌธ"> | ||
| {children} | ||
| </main> | ||
| ); | ||
| } |
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,172 @@ | ||
| "use client"; | ||
|
|
||
| import { cn } from "@/lib/utils"; | ||
| import { Button } from "@/shared/button"; | ||
| import { Icon } from "@/shared/Icon"; | ||
| import { Input } from "@/shared/input"; | ||
| import { useAuthFormStore } from "@/stores/authForm.store"; | ||
| import Link from "next/link"; | ||
| import type { ChangeEvent, FormEvent } from "react"; | ||
|
|
||
| export function LoginForm() { | ||
| const { | ||
| email, | ||
| password, | ||
| emailError, | ||
| passwordError, | ||
| isPasswordVisible, | ||
| setEmail, | ||
| setPassword, | ||
| clearEmailError, | ||
| clearPasswordError, | ||
| togglePasswordVisible, | ||
| validateLogin, | ||
| } = useAuthFormStore(); | ||
|
|
||
| const handleSubmit = (event: FormEvent<HTMLFormElement>) => { | ||
| event.preventDefault(); // ๊ธฐ๋ณธ form submit ๋์ ๋ง๊ธฐ | ||
|
|
||
| const isValid = validateLogin(); | ||
| if (!isValid) { | ||
| // ์๋ฌ ์ํ/๊ฐ ์ด๊ธฐํ๋ ์คํ ์ด์์ ์ด๋ฏธ ์ฒ๋ฆฌ | ||
| return; | ||
| } | ||
|
|
||
| // TODO: ์ค์ ๋ก๊ทธ์ธ ์์ฒญ ๋ก์ง | ||
| // ex) await login({ email, password }); | ||
| }; | ||
|
|
||
| const handleEmailChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| setEmail(event.target.value); | ||
| }; | ||
|
|
||
| const handlePasswordChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| setPassword(event.target.value); | ||
| }; | ||
|
|
||
| return ( | ||
| <form | ||
| className={cn( | ||
| "flex flex-col gap-10 rounded-2xl border border-[var(--color-gray-200)] bg-[var(--color-white)] px-4 py-6", | ||
| "md:px-6 md:py-8", | ||
| )} | ||
| aria-label="๋ก๊ทธ์ธ ํผ" | ||
| onSubmit={handleSubmit} | ||
| noValidate | ||
| > | ||
| {/* ์ด๋ฉ์ผ ํ๋ */} | ||
| <div className="flex w-full max-w-[36.6rem] flex-col gap-4 mx-auto"> | ||
| <div className="flex items-center justify-between"> | ||
| <label htmlFor="login-email" className="t-14-m text-[var(--color-gray-700)]"> | ||
| ์ด๋ฉ์ผ | ||
| </label> | ||
|
|
||
| {emailError && ( | ||
| <span className="t-12-m text-[var(--color-red-500)]">์ด๋ฉ์ผ ์ ๋ณด๋ฅผ ํ์ธํด ์ฃผ์ธ์.</span> | ||
| )} | ||
| </div> | ||
| <Input | ||
| id="login-email" | ||
| name="email" | ||
| type="email" | ||
| placeholder="์ด๋ฉ์ผ์ ์ ๋ ฅํ์ธ์" | ||
| status={emailError ? "error" : "default"} | ||
| autoComplete="email" | ||
| required | ||
| value={email} | ||
| onChange={handleEmailChange} | ||
| onFocus={clearEmailError} // ๋ค์ ํด๋ฆญํ๋ฉด ์๋ฌ ํด์ โ ๊ฒ์ ํ ๋๋ฆฌ | ||
| /> | ||
| </div> | ||
|
|
||
| {/* ๋น๋ฐ๋ฒํธ ํ๋ + ํ์ ํ ๊ธ */} | ||
| <div className="flex w-full max-w-[36.6rem] flex-col gap-4 mx-auto"> | ||
| <div className="flex items-center justify-between"> | ||
| <label htmlFor="login-password" className="t-14-m text-[var(--color-gray-700)]"> | ||
| ๋น๋ฐ๋ฒํธ | ||
| </label> | ||
|
|
||
| {passwordError && ( | ||
| <span className="t-12-m text-[var(--color-red-500)]">๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด ์ฃผ์ธ์.</span> | ||
| )} | ||
| </div> | ||
| <div className="relative w-full"> | ||
| <Input | ||
| id="login-password" | ||
| name="password" | ||
| type={isPasswordVisible ? "text" : "password"} | ||
| status={passwordError ? "error" : "default"} | ||
| autoComplete="current-password" | ||
| required | ||
| className="w-full pr-10" | ||
| value={password} | ||
| onChange={handlePasswordChange} | ||
| onFocus={clearPasswordError} // ๋ค์ ํด๋ฆญํ๋ฉด ์๋ฌ ํด์ | ||
| /> | ||
| {/* ๋น๋ฐ๋ฒํธ ํ์/์จ๊น ํ ๊ธ ์์ด์ฝ */} | ||
| <button | ||
| type="button" | ||
| className="absolute right-5 top-1/2 -translate-y-1/2 cursor-pointer" | ||
| aria-label={isPasswordVisible ? "๋น๋ฐ๋ฒํธ ์จ๊ธฐ๊ธฐ" : "๋น๋ฐ๋ฒํธ ํ์"} | ||
| aria-pressed={isPasswordVisible} | ||
| onClick={togglePasswordVisible} | ||
| > | ||
| <Icon | ||
| name={isPasswordVisible ? "eyeOff" : "eye"} | ||
| size={18} | ||
| className="text-[var(--color-gray-500)]" | ||
| /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* ๋ก๊ทธ์ธ ๋ฒํผ */} | ||
| <div className="w-full max-w-[36.6rem] mx-auto"> | ||
| <Button type="submit" preset="signup" bg="basic" className="w-full"> | ||
| ๋ก๊ทธ์ธ | ||
| </Button> | ||
| </div> | ||
|
|
||
| {/* ํฌํผ ๋งํฌ: ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ / ํ์๊ฐ์ */} | ||
| <div className="flex w-full max-w-[36.6rem] flex-col gap-4 text-center mx-auto"> | ||
| <p className="t-14-m text-[var(--color-gray-600)]"> | ||
| ๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์ จ๋์?{" "} | ||
| <Link | ||
| href="/forgot-password" | ||
| className="t-14-m text-[var(--color-gray-900)] underline-offset-2 hover:underline" | ||
| > | ||
| ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ | ||
| </Link> | ||
| </p> | ||
| <p className="t-14-m text-[var(--color-gray-600)]"> | ||
| ํ์์ด ์๋์ ๊ฐ์?{" "} | ||
| <Link | ||
| href="/signup" | ||
| className="t-14-m text-[var(--color-gray-900)] underline-offset-2 hover:underline" | ||
| > | ||
| ํ์๊ฐ์ ํ๊ธฐ | ||
| </Link> | ||
| </p> | ||
| </div> | ||
|
|
||
| {/* ๊ฐํธ ๋ก๊ทธ์ธ + ์์ ๋ฒํผ */} | ||
| <div className="flex w-full max-w-[36.6rem] flex-col gap-4 pt-2 mx-auto"> | ||
| <div className="flex items-center gap-4 w-full"> | ||
| <div className="h-px flex-1 bg-[var(--color-gray-200)]" /> | ||
| <span className="t-14-m text-[var(--color-gray-500)]">๊ฐํธ ๋ก๊ทธ์ธ</span> | ||
| <div className="h-px flex-1 bg-[var(--color-gray-200)]" /> | ||
| </div> | ||
|
|
||
| <div className="flex w-full flex-col items-center gap-5"> | ||
| <Button type="button" preset="signup" bg="kakao" className="w-full"> | ||
| <span>์นด์นด์คํก์ผ๋ก ๋ก๊ทธ์ธ</span> | ||
| </Button> | ||
|
|
||
| <Button type="button" preset="signup" bg="google" className="w-full"> | ||
| <span>๊ตฌ๊ธ๋ก ๋ก๊ทธ์ธ</span> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } |
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
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,55 @@ | ||
| import type { AuthFormState } from "@/types/authForm"; | ||
| import { create } from "zustand"; | ||
|
|
||
| export const useAuthFormStore = create<AuthFormState>((set, get) => ({ | ||
| email: "", | ||
| password: "", | ||
| emailError: false, | ||
| passwordError: false, | ||
| isPasswordVisible: false, | ||
|
|
||
| setEmail: (value) => set({ email: value }), | ||
| setPassword: (value) => set({ password: value }), | ||
|
|
||
| clearEmailError: () => set({ emailError: false }), | ||
| clearPasswordError: () => set({ passwordError: false }), | ||
|
|
||
| togglePasswordVisible: () => set((state) => ({ isPasswordVisible: !state.isPasswordVisible })), | ||
|
|
||
| validateLogin: () => { | ||
| const { email, password } = get(); | ||
|
|
||
| let emailError = false; | ||
| let passwordError = false; | ||
|
|
||
| // ์ด๋ฉ์ผ: ๋น์ด ์๊ฑฐ๋ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ผ๋ฉด ์๋ฌ | ||
| const trimmedEmail = email.trim(); | ||
| const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedEmail); | ||
|
|
||
| if (!trimmedEmail || !isValidEmail) { | ||
| emailError = true; | ||
| } | ||
|
|
||
| // ๋น๋ฐ๋ฒํธ: 6์๋ฆฌ ์ด์ + ํน์๋ฌธ์ 1๊ฐ ์ด์ | ||
| const hasMinLength = password.length >= 6; | ||
| const hasSpecialChar = /[^A-Za-z0-9]/.test(password); | ||
|
|
||
| if (!hasMinLength || !hasSpecialChar) { | ||
| passwordError = true; | ||
| } | ||
|
|
||
| // ํ๋๋ผ๋ ์๋ฌ๊ฐ ์์ผ๋ฉด ํด๋น ํ๋ ๊ฐ ์ด๊ธฐํ + ์๋ฌ ํ๋๊ทธ ์ธํ | ||
| if (emailError || passwordError) { | ||
| set({ | ||
| email: emailError ? "" : email, | ||
| password: passwordError ? "" : password, | ||
| emailError, | ||
| passwordError, | ||
| }); | ||
| return false; | ||
| } | ||
|
|
||
| set({ emailError: false, passwordError: false }); | ||
| return true; | ||
| }, | ||
| })); | ||
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,17 @@ | ||
| export interface AuthFormState { | ||
| email: string; | ||
| password: string; | ||
| emailError: boolean; | ||
| passwordError: boolean; | ||
| isPasswordVisible: boolean; | ||
|
|
||
| setEmail: (value: string) => void; | ||
| setPassword: (value: string) => void; | ||
|
|
||
| clearEmailError: () => void; | ||
| clearPasswordError: () => void; | ||
|
|
||
| togglePasswordVisible: () => void; | ||
|
|
||
| validateLogin: () => boolean; | ||
| } |
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.
The validator trims whitespace to check the email format but, in the success path, the store keeps the original
emailstring (emailErrorremains false and nosetoccurs with the trimmed value). A user who types" [email protected] "will pass validation, yet the state still contains the leading/trailing spaces; any subsequent login request that readsemailfrom the store will send the untrimmed value and likely be rejected serverโside despite the UI reporting success. Store the trimmed email when validation passes or fail validation if whitespace is present.Useful? React with ๐ย / ๐.