-
Notifications
You must be signed in to change notification settings - Fork 2
✨Feat: 로그인 폼 구현 #52
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
✨Feat: 로그인 폼 구현 #52
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c9eb531
📁chore: 폴더 경로 수정
Insung-Jo 923c94d
🎨style: 일부 스타일 수정
Insung-Jo 31c4129
✨feat: 로그인 제출 훅 구현
Insung-Jo 5512b13
✨feat: 로그인 유효성 검증 스키마 추가
Insung-Jo 44191a5
✨feat: 로그인 폼 구현 및 페이지 적용
Insung-Jo a134c07
🫧modify: useForm 일부 수정
Insung-Jo dd936d4
🎨style: 일부 스타일 추가
Insung-Jo d8d135a
🫧modify: useAuth 일부 수정
Insung-Jo ffb2d74
🫧modify: 조건부 스타일링 수정
Insung-Jo fc201c7
🫧modify: 함수명 변경 및 적용
Insung-Jo f9a0262
🫧modify: 버튼 내용 변경
Insung-Jo b227c2a
🎨style: 스타일 수정
Insung-Jo b10a37a
🐛fix: 코드래빗 리뷰 반영
Insung-Jo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 'use client' | ||
|
|
||
| import LoginForm from '@/app/features/auth/components/LoginForm' | ||
|
|
||
| export default function Login() { | ||
| return ( | ||
| <> | ||
| <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
Empty file.
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,60 @@ | ||
| 'use client' | ||
|
|
||
| import Input from '@components/Input' | ||
| import { cn } from '@lib/cn' | ||
| import { useForm } from 'react-hook-form' | ||
|
|
||
| import { useLoginSubmit } from '../hooks/useLoginSubmit' | ||
| import { loginValidation } from '../schemas/loginValidation' | ||
| import { LoginRequest } from '../types/auth.type' | ||
|
|
||
| export default function LoginForm() { | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isSubmitting, isValid }, | ||
| } = useForm<LoginRequest>({ | ||
| mode: 'onChange', | ||
| defaultValues: { | ||
| email: '', | ||
| password: '', | ||
| }, | ||
| }) | ||
|
|
||
| const { submit } = useLoginSubmit() | ||
| const showEmailError = !!errors.email | ||
| const showPasswordError = !!errors.password | ||
|
|
||
| return ( | ||
| <form className="flex flex-col gap-16" onSubmit={handleSubmit(submit)}> | ||
| <Input | ||
| labelName="이메일" | ||
| type="email" | ||
| placeholder="이메일 입력" | ||
| autoComplete="email" | ||
| {...register('email', loginValidation.email)} | ||
| hasError={showEmailError} | ||
| errorMessage={errors.email?.message} | ||
| /> | ||
| <Input | ||
| labelName="비밀번호" | ||
| type="password" | ||
| placeholder="비밀번호 입력" | ||
| autoComplete="off" | ||
| {...register('password', loginValidation.password)} | ||
| hasError={showPasswordError} | ||
| errorMessage={errors.password?.message} | ||
| /> | ||
| <button | ||
| type="submit" | ||
| className={cn( | ||
| 'mt-8 h-50 w-full rounded-8 text-lg font-medium text-white', | ||
| isValid && !isSubmitting ? 'BG-blue' : 'BG-blue-disabled', | ||
| )} | ||
| disabled={!isValid || isSubmitting} | ||
| > | ||
| 로그인 | ||
| </button> | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import axios from 'axios' | ||
| import { useRouter } from 'next/navigation' | ||
| import { toast } from 'sonner' | ||
|
|
||
| import { LoginRequest } from '../types/auth.type' | ||
| import { useAuth } from './useAuth' | ||
|
|
||
| export function useLoginSubmit() { | ||
| const { login } = useAuth() | ||
| const router = useRouter() | ||
|
|
||
| async function submit(data: LoginRequest) { | ||
| try { | ||
| await login(data) | ||
| toast.success('로그인 성공') | ||
| router.push('/mydashboard') | ||
| } catch (e: unknown) { | ||
| if (axios.isAxiosError(e)) { | ||
| const message = e.response?.data?.message | ||
| toast.error(message ?? '로그인 실패') | ||
| } else { | ||
| toast.error('알 수 없는 에러 발생') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { submit } | ||
| } |
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,16 @@ | ||
| export const loginValidation = { | ||
| email: { | ||
| required: '이메일을 입력해 주세요.', | ||
| pattern: { | ||
| value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, | ||
| message: '유효한 이메일 주소를 입력해주세요', | ||
| }, | ||
| }, | ||
| password: { | ||
| required: '비밀번호를 입력해 주세요.', | ||
| minLength: { | ||
| value: 8, | ||
| message: '비밀번호는 최소 8자 이상이어야 합니다.', | ||
| }, | ||
| }, | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.