-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/13 로그인 회원가입 리팩토링 #15
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
Open
dlcks0601
wants to merge
7
commits into
develop
Choose a base branch
from
feature/13-로그인-회원가입-리팩토
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "feature/13-\uB85C\uADF8\uC778-\uD68C\uC6D0\uAC00\uC785-\uB9AC\uD329\uD1A0"
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b01b731
[Feat] 토큰 유틸 함수
dlcks0601 d69dcce
[Refactor] api 연결만을 위해 최소화
dlcks0601 1109f4c
[Refactor] 필요없는 부분 삭제
dlcks0601 5708cdc
[Refactor] 상태관리로 로그인
dlcks0601 6839ecd
[Refactor] store로 내보내기
dlcks0601 54e4c69
[Refactor] 상태관리 코드 최적화
dlcks0601 5f45095
[Feat] 인증 관련 타입
dlcks0601 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 |
|---|---|---|
| @@ -1,70 +1,22 @@ | ||
| import httpClient from './http.api'; // Axios 인스턴스 가져오기 | ||
| import { JoinProps } from '@/pages/JoinPage'; | ||
| import { LoginProps } from '@/pages/LoginPage'; | ||
| import { JoinProps } from '@/pages/JoinPage'; | ||
| import httpClient from './http.api'; | ||
|
|
||
| // 회원가입 요청 | ||
| export const join = async (userData: JoinProps) => { | ||
| try { | ||
| const { data, status } = await httpClient.post('/api/users/join', userData); | ||
|
|
||
| if (status === 200) { | ||
| console.log('회원가입 성공:', data); | ||
| return data; | ||
| } else if (status === 400 && data.message.includes('입력해주세요')) { | ||
| console.error('필수 입력값 없음:', data.message); | ||
| throw new Error(data.message); | ||
| } else if (status === 400 && data.message.includes('중복된')) { | ||
| console.error('중복 오류:', data.message); | ||
| throw new Error(data.message); | ||
| } else { | ||
| throw new Error('알 수 없는 회원가입 에러가 발생했습니다.'); | ||
| } | ||
| } catch (error) { | ||
| console.error('회원가입 요청 중 에러 발생:', error); | ||
| throw new Error('회원가입 요청에 실패했습니다. 관리자에게 문의하세요.'); | ||
| } | ||
| export const join = async (data: JoinProps) => { | ||
| const response = await httpClient.post('/api/users/join', data); | ||
| return response.data; | ||
| }; | ||
|
|
||
| interface LoginResponse { | ||
| export interface LoginResponse { | ||
| message: any; | ||
| success: boolean; | ||
| token?: string; | ||
| } | ||
|
|
||
| // 로그인 요청 | ||
| export const login = async (data: LoginProps): Promise<LoginResponse> => { | ||
| try { | ||
| const { data: responseData, status } = await httpClient.post<LoginResponse>( | ||
| '/api/users/login', | ||
| data | ||
| ); | ||
|
|
||
| if (status === 200 && responseData.success) { | ||
| console.log('로그인 성공:', responseData); | ||
| return responseData; | ||
| } else if ( | ||
| status === 400 && | ||
| responseData.message.includes('입력해주세요') | ||
| ) { | ||
| console.error('필수 입력값 없음:', responseData.message); | ||
| throw new Error(responseData.message); | ||
| } else if ( | ||
| status === 404 && | ||
| responseData.message.includes('등록되지 않은 이메일') | ||
| ) { | ||
| console.error('등록되지 않은 이메일:', responseData.message); | ||
| throw new Error(responseData.message); | ||
| } else if ( | ||
| status === 401 && | ||
| responseData.message.includes('비밀번호가 틀렸습니다') | ||
| ) { | ||
| console.error('비밀번호 오류:', responseData.message); | ||
| throw new Error(responseData.message); | ||
| } else { | ||
| throw new Error('알 수 없는 로그인 에러가 발생했습니다.'); | ||
| } | ||
| } catch (error) { | ||
| console.error('로그인 요청 중 에러 발생:', error); | ||
| throw new Error('로그인 요청에 실패했습니다. 관리자에게 문의하세요.'); | ||
| } | ||
| export const login = async (data: LoginProps) => { | ||
| const response = await httpClient.post<LoginResponse>( | ||
| '/api/users/login', | ||
| data | ||
| ); | ||
| return response.data; | ||
| }; |
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
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.
컴포넌트 렌더링 시에 영향을 끼치는 작업들은 useEffect 내부에서 처리해야합니다.
물론 지금은 아무런 문제가 없어 보이고 잘 리다이렉트 되는 것 같지만,
이는 불필요한 렌더링을 야기할 수 있기 때문에 react에서는 권장하지 않는 형태입니다 😄
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.
warning이 떠서 삭제했습니다!