-
Notifications
You must be signed in to change notification settings - Fork 2
[#56] 로그인 기능 구현 #107
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
[#56] 로그인 기능 구현 #107
Conversation
src/lib/api/auth.ts
Outdated
| // 로그인 요청 처리 | ||
| export const signIn = async (data: SignInRequest): Promise<SignInReponse> => { | ||
| try { | ||
| const response = await apiClient.post('/v1/auth/sign-in', data, { | ||
| // withCredentials: true, | ||
| }) | ||
| console.log('로그인 성공:', response.data) | ||
| return response.data | ||
| console.log(response.data.result) | ||
| } catch (error) { | ||
| console.error('로그인 실패:', (error as Error).message) | ||
| throw error // 에러를 호출자에게 전달 | ||
| } | ||
| } |
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.
export const signIn = (data: SignInRequest) => {
return apiClient.post('/v1/auth/sign-in', data);
};위와 같이 리팩토링을 하는 게 좋을 것 같다고 생각이 들어요.
이유
- 리팩토링 전
- response.data를 리턴 (이러면 response 객체의 다른 상태에 접근 불가)
- try-catch를 통해 에러를 핸들링하고 throw error로 재전달
- 리팩토링 후
- response 객체 전체를 리턴
- 호출자가 response.data, response.status, response.headers 등 다양한 정보를 활용할 수 있음
- try-catch가 제거되어 API 호출부에서 에러 처리를 위임
즉,
- response.data만 반환하면 API 응답의 세부 정보(예: HTTP 상태 코드, 헤더, 요청 설정)를 호출자가 활용할 수 없습니다.
- 리팩토링 후에는 호출자가 response 객체 전체를 활용할 수 있어 확장성이 증가할 것 같네요 -> 더 많은 정보를 호출자에게 제공이 가능함
- 에러 핸들링 책임 위임
- try-catch를 함수 내부에서 처리하지 않으면, 호출자가 에러 처리를 커스터마이징할 수 있습니다.
예를 들어, 호출자가 try-catch를 통해 로깅, 재시도, 사용자 알림 등 다양한 방식으로 에러를 다룰 수 있을 것 같아요 -> 에러 처리도 호출자가 하는 게 나을 것 같아요.
만약 함수 내부에서 try-catch로 처리했을 때 에러가 나면 사용자는 감지를 못 할 수가 있습니다. (함수 내부에서 에러를 console.log로 출력하고 종료하면, 호출자는 더 이상 에러를 받을 수 없고, 사용자 경험이나 문제 해결 방식을 제어할 수 없습니다.)
@KingNono1030 @yellowjang 의견 부탁드립니다!
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.
의견 감사합니다
…h a light type correction
📌 PR 템플릿
🏷️ PR 타입 (PR Type)
📝 요약 (Summary)
🔍 상세 내용 (Describe your changes)
🔗 관련 이슈 또는 링크 (Issue Number or Link)
#56
✅ 체크리스트 (Checklist)
📸 스크린샷 (선택 사항)
1. process (?) 에러
2. tsconfig.json 파일에서의 에러
📝 기타 사항
아직 user 정보를 get 하는 건 없지만, 로그인이 성공하면 해당 post 요청에 대한 response.result 로 들어가면 볼 수 있긴 합니다! 콘솔에 찍히도록 일단 해두었습니다