-
Notifications
You must be signed in to change notification settings - Fork 0
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
[기능구현] 회원가입 #59
[기능구현] 회원가입 #59
Conversation
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.
https://vite.dev/guide/env-and-mode.html
보통 이런식으로 백엔드 주소를 환경변수 .env
파일로 가려놓는편입니다.
src/pages/common/register/index.tsx
Outdated
const mutation = useMutation({ | ||
mutationFn: registerUser, | ||
onSuccess: (data: SignupApiResponse) => { | ||
// 207 (이미 이메일이 존재하면 Multi-Status) | ||
if ('status' in data && data.status === 207) { | ||
alert(data.detail); | ||
} else { | ||
// 200 (성공) -> 토큰 저장 | ||
console.log(data); | ||
// 타입가드 | ||
if ('accessToken' in data) { | ||
authLocalStorage.set(data.accessToken); | ||
authLocalStorage.set(data.refreshToken); | ||
alert('회원가입이 완료되었습니다.'); | ||
// 유저 타입에 따라 네비게이션 | ||
if (data.isSinitto === 'true') { | ||
navigate(RouterPath.ROOT); | ||
// navigate(RouterPath.SINITTO_HOME); | ||
} else { | ||
navigate(RouterPath.ROOT); | ||
// navigate(RouterPath.GUARD_HOME); | ||
} | ||
} | ||
} | ||
}, | ||
onError: (error: AxiosError) => { | ||
if (error.response && error.response.data) { | ||
alert('회원가입 중 오류가 발생했습니다.'); | ||
} else { | ||
alert('회원가입 중 네트워크 오류가 발생했습니다.'); | ||
} | ||
}, | ||
}); |
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.
이렇게 한번에 쓰는것 보다 hook 으로 분리해서 사용하는게 더 좋아보입니다!
export const BASE_URL = 'http://43.201.254.198:8080'; | ||
|
||
export const fetchInstance = initInstance({ | ||
baseURL: 'https://api.example.com', | ||
baseURL: 'http://43.201.254.198:8080', |
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.
이부분은 제가 수정할게요..
type StorageKey = { | ||
accessToken?: string; | ||
}; | ||
|
||
const initStorage = <T extends keyof StorageKey>(key: T, storage: Storage) => { | ||
const storageKey = `${key}`; | ||
|
||
const get = (): StorageKey[T] => { | ||
const value = storage.getItem(storageKey); | ||
return value as StorageKey[T]; | ||
}; | ||
|
||
const set = (value: StorageKey[T]) => { | ||
if (value == undefined || value == null) { | ||
return storage.removeItem(storageKey); | ||
} | ||
const stringifiedValue = JSON.stringify(value); | ||
storage.setItem(storageKey, stringifiedValue); | ||
}; | ||
|
||
return { get, set }; | ||
}; | ||
|
||
export const authLocalStorage = initStorage('accessToken', localStorage); |
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.
이 코드는 step2에서 강사님이 사용하신 코드 같은데, 혹시 어떤 기능을 하는지 알 수 있을까요? 제가 이 코드에 대해 잘 이해를 못해서..
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.
src/shared/hooks/useRegister.ts
Outdated
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.
useRegister.ts는 회원가입 페이지에서만 쓰이는데, pages/common/register 폴더 안에 /api 또는 /api/hooks를 만들어야할 것 같습니다.
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.
아 그렇네요!
#️⃣ 연관된 이슈
📝 작업 내용
[기능구현] 회원가입
스크린샷 (선택)
💬 리뷰 요구사항(선택)
⏰ 현재 버그
✏ Git Close