-
Notifications
You must be signed in to change notification settings - Fork 2
✨Feat: 로그인 페이지 구현 #65
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
Changes from all commits
990954d
06e6a2e
33bbfcf
edc091e
54b57ba
9d0aa93
3874b83
2754f34
e1810b0
925f914
adbba55
fdbd6c9
f40578c
47bf3d6
f4bdea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export default function DashboardLayout({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode | ||
| }) { | ||
| return ( | ||
| <div className="flex min-h-screen w-full items-center justify-center"> | ||
| <div className="flex w-520 flex-col items-center justify-center gap-24 px-12 sm:px-0"> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,26 @@ | ||
| 'use client' | ||
| import Link from 'next/link' | ||
| import { useEffect, useState } from 'react' | ||
|
|
||
| import AuthLogo from '@/app/features/auth/components/AuthLogo' | ||
| import LoginForm from '@/app/features/auth/components/LoginForm' | ||
|
|
||
| export default function Login() { | ||
| const [mounted, setMounted] = useState(false) | ||
| useEffect(() => setMounted(true), []) | ||
| if (!mounted) { | ||
| return null | ||
| } | ||
| return ( | ||
| <> | ||
| <AuthLogo text="오늘도 만나서 반가워요!" /> | ||
| <LoginForm /> | ||
| <p className="text-16 font-normal"> | ||
| 회원이 아니신가요?{' '} | ||
| <Link className="Text-violet underline" href="/signup"> | ||
| 회원가입하기 | ||
| </Link> | ||
| </p> | ||
Insung-Jo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { showError, showSuccess } from '@lib/toast' | ||
| import { useMutation } from '@tanstack/react-query' | ||
| import type { AxiosError } from 'axios' | ||
| import axios from 'axios' | ||
| import { useRouter } from 'next/navigation' | ||
|
|
||
| import { login } from '../api/authApi' | ||
| import { LoginRequest, LoginResponse } from '../types/auth.type' | ||
| import { useAuth } from './useAuth' | ||
|
|
||
| export function useLoginMutation() { | ||
| const router = useRouter() | ||
| const { updateAuthState } = useAuth() | ||
|
|
||
| return useMutation<LoginResponse, AxiosError | Error, LoginRequest>({ | ||
| mutationFn: login, | ||
| onSuccess: async (response) => { | ||
| updateAuthState(response) | ||
| showSuccess('로그인에 성공하셨습니다!') | ||
| await new Promise((resolve) => setTimeout(resolve, 400)) | ||
| router.push('/mydashboard') | ||
| }, | ||
| onError: (error) => { | ||
| if (axios.isAxiosError(error)) { | ||
| const severMessage = ( | ||
| error.response?.data as { message?: string } | undefined | ||
| )?.message | ||
| const fallback = error.message || '로그인 실패' | ||
| showError(severMessage ?? fallback) | ||
| } else { | ||
| showError('알 수 없는 에러 발생') | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
|
Comment on lines
+1
to
+35
Contributor
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. react-query 사용하여 함수 작성해주셨군용!!
Author
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. 우선 일관성의 목적으로 기존 try-catch에서 바꾸게 되었습니다! 현재 적용 해봤을 때 느낄 수 있는 장점은 우선 가독성 측면에서도 분리가 되어있어서 코드를 이해할 때 수월하고 |
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.