[FEATURE] Clerk 토큰 기반 보호 API 요청 구조 공통화#42
Merged
Conversation
minsoo0506
approved these changes
May 19, 2026
minsoo0506
left a comment
There was a problem hiding this comment.
공통 API 클라이언트 분리, { data } 응답 언랩, 인증/비인증 요청 분리, 기존 auth/me와 terms 호출부 전환 모두 문제 없어 보입니다!
수고하셨습니다 :)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #41
개요
Clerk 기반 Google 로그인 및 회원 동기화 흐름은 유지하면서, 이후 백엔드 보호 API를 호출할 때 재사용할 수 있는 공통 API 요청 구조를 정리했습니다.
기존 프론트엔드에는 로그인 성공 후
/api/v1/auth/me를 호출해 Clerk 사용자와 백엔드member를 동기화하는 흐름이 이미 구현되어 있었습니다. 이번 작업에서는/auth/me를 새 로그인 API처럼 새로 연동하지 않고, 기존 역할인 Clerk JWT 검증 및 member 확인/동기화 API로 유지했습니다.대신 이후
analyses,saved-links, 북마크, 삭제 API처럼 인증이 필요한 API를 연동할 때 ClerkgetToken()으로 받은 토큰을Authorization: Bearer {token}헤더에 일관되게 포함할 수 있도록 공통 API 클라이언트를 추가했습니다.또한 백엔드 응답이
{ data: ... }형태로 내려오는 구조를 공통으로 처리하고, API base URL 설정과 에러 응답 처리도 한곳에서 관리하도록 정리했습니다. 기존 약관 API처럼 인증이 필요 없는 요청은 비인증 요청 함수로 분리해 공통 구조와 충돌 없이 동작하도록 변경했습니다.주요 구현 내용
api/api-client.ts추가http://10.0.2.2:8080으로 설정http://localhost:8080으로 설정EXPO_PUBLIC_API_BASE_URL환경변수로 API base URL 재정의 가능하도록 처리ApiResponse<T>응답의{ data: ... }래핑 구조 공통 해제ApiError타입 추가message,code,errors를 공통 에러 객체로 변환204 No Content응답 처리 추가publicApiRequest추가authenticatedApiRequest추가getToken()결과를 검증하고 세션 토큰을 가져오는getClerkSessionToken추가Authorization: Bearer {token}헤더 자동 주입/api/v1/auth/me회원 동기화 흐름을 공통 API 클라이언트 기반으로 변경파일별 역할
api/api-client.ts: API base URL 설정, 공통 요청 함수, 인증/비인증 요청 분리, Clerk 토큰 주입,{ data }응답 래핑 해제, 공통 에러 처리services/auth-api.ts: 기존/api/v1/auth/me회원 동기화 API 호출 유지, 공통 API 클라이언트 기반으로 요청 방식 변경api/terms.ts: 약관 API의 자체 base URL/응답 파싱/에러 처리 로직을 제거하고publicApiRequest기반으로 변경해결한 이슈 목록
/api/v1/auth/me호출 위치와 역할 확인/auth/me를 새 로그인 API가 아닌 기존 member 확인/동기화 흐름으로 유지/auth/me사전 호출에만 의존하지 않고 보호 API 요청마다 Clerk 토큰을 포함할 수 있는 구조로 정리services/auth-api.ts의 역할과 유지해야 할 동작 확인api/terms.ts의 base URL, 응답 파싱, 에러 처리 방식 확인getToken()으로 받은 토큰을 보호 API 요청 헤더에 재사용 가능하게 주입{ data: ... }응답 래퍼를 공통으로 처리체크 사항
/api/v1/auth/me200 응답 확인ApiResponse[data=MeResponse[publicId=...]]응답 확인member동기화 확인GET /api/v1/terms/terms_of_service200 응답 확인{ data: ... }구조로 내려오는 것 확인참고
이번 작업은 보호 API 요청 구조를 공통화하는 기반 작업입니다.
분석 요청
POST /api/v1/analyses, 분석 polling, 저장 링크POST /api/v1/saved-links, 북마크/삭제 API 실제 화면 연동은 후속 작업에서 진행합니다.