- auth/negotiation 도메인별 api/keys/queries/mutations/type 5파일 구조 - axios 인스턴스: access token 주입, 434 만료 시 refresh 자동 재발급(단일 비행) 후 원요청 재시도, 433/435/1203(TOKEN_REVOKED) 시 세션 종료 처리 - HTTP 200 + result.success=false 비즈니스 에러를 ApiError 로 변환, 에러코드별 한국어 메시지 맵(getApiErrorMessage) 제공 - 토큰 localStorage 저장소(tokenStorage) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
21 lines
622 B
TypeScript
21 lines
622 B
TypeScript
// 인증 도메인의 조회(useQuery) 훅.
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { tokenStorage } from '@/apis/tokenStorage'
|
|
import { authApi } from './auth.api'
|
|
import { authKeys } from './auth.keys'
|
|
import { toAuthUser } from './auth.type'
|
|
|
|
/**
|
|
* 현재 로그인 유저 정보 조회.
|
|
* 토큰이 있을 때만 활성화되며, AuthUser(카멜케이스)로 가공해 반환한다.
|
|
*/
|
|
export function useMeQuery() {
|
|
return useQuery({
|
|
queryKey: authKeys.me(),
|
|
queryFn: authApi.me,
|
|
enabled: tokenStorage.hasToken(),
|
|
staleTime: 5 * 60 * 1000, // 5분
|
|
select: toAuthUser,
|
|
})
|
|
}
|