[Enhancement] 백엔드 auth 변경사항 반영 - #112
Open
danjee2009 wants to merge 4 commits into
Open
Conversation
토큰이 없을 때 400 대신 401 {message}가 내려오고, 만료된 토큰의 401과
스키마가 하나로 통일됐다.
- 401/403 상태코드별 폴백 문구를 extractErrorMessage에 추가
- 세션 정리와 로그인 이동을 handleAuthenticationFailure로 통합
- 이미 로그인/회원가입 화면이면 리다이렉트하지 않도록 방어
- 인터셉터를 타지 않는 SSE 구독에서 401/403을 직접 처리
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
토큰을 안 보내도 200을 주던 엔드포인트들이 이제 401을 반환한다. 기존 인터셉터는 토큰이 없으면 헤더 없이 그대로 요청을 보내 401만 받아왔다. apiInstance와 chatInstance는 재발급까지 시도한 뒤에도 토큰이 없으면 요청을 보내지 않고 로그인 흐름으로 넘긴다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
모든 요청이 토큰을 요구하게 되면서, 토큰이 없는 상태의 병렬 요청이 각각 재발급을 호출한다. 리프레시 토큰을 회전시키면 뒤이은 호출이 실패해 멀쩡한 세션이 로그아웃될 수 있어, 진행 중인 재발급 요청 하나를 공유한다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
Author
|
@claude PR리뷰 |
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.
변경 내용
백엔드 인증 계약 변경 3가지를 웹에 반영했습니다.
1. 토큰 누락 시 401 통일 (
361bcc9)토큰이 없을 때
400 {detail, instance, status, title}대신401 {message}가 내려오고, 만료 토큰의 401과 스키마가 하나로 합쳐졌습니다.axiosInstance의 401 인터셉터 한 곳에 모여 있어, 옮길 분기 대신 그 흐름을 정리했습니다.handleAuthenticationFailure()로 통합하고, 이미/login·/signup이면 리다이렉트하지 않도록 막았습니다.extractErrorMessage에 상태코드별 폴백을 추가했습니다. 본문이 비었거나 HTML이 올 때 이전에는 호출부의 일반 문구가 나가던 자리에로그인이 필요합니다./접근 권한이 없습니다.가 나갑니다.fetch)이 401에AI SSE request failed: 401만 던지고 세션 정리도 안 했습니다. 서버 메시지를 꺼내 쓰고 401이면 세션도 정리합니다.2. 토큰 미첨부 엔드포인트에 헤더 보장 (
3af1484)기존 인터셉터는 토큰이 없으면 헤더 없이 그냥 요청을 보냈습니다. 지금까지는 공개 엔드포인트가 200을 주니 통했지만 이제는 401만 돌아옵니다.
apiInstance·chatInstance는 재발급까지 시도한 뒤에도 토큰이 없으면 요청을 보내지 않고 로그인 흐름으로 넘깁니다.표의 9개 중 웹이 실제로 호출하는 건
POST /api/persona/save하나입니다. 나머지(persona 조회 3개, answer 조회 2개, question 3개)는 호출부가 없습니다./api/questions/tailor는 이름만 비슷한 별개 엔드포인트라 그대로 뒀습니다.3. 조회 403
403은 인터셉터를 그냥 통과해 세션이 유지되고, 서버 메시지(
본인의 답변만 볼 수 있습니다.)가 그대로 화면에 뜹니다. 404를 기대하던 분기도 코드에 없어 별도 처리는 넣지 않았습니다.+ 재발급 중복 호출 방지 (
6ae900d)모든 요청이 토큰을 요구하게 되면서 생긴 부수 효과입니다. 토큰이 없는 상태의 병렬 요청(피드백 상세는 2개를 동시에 부릅니다)이
/api/v1/auth/refresh를 각각 때립니다. 리프레시 토큰을 회전시키는 서버라면 두 번째가 실패해 멀쩡한 세션이 로그아웃될 수 있어, 진행 중인 재발급 하나를 공유하도록 묶었습니다.관련 이슈
테스트 방법
npm run lint(기존 경고 1건 외 clean),npm run build통과. 커밋 3개 각각 독립적으로 타입체크 통과를 확인했습니다.백엔드가 ngrok URL이라 브라우저 실동작 확인은 못 했습니다. 서버가 떠 있을 때 아래를 봐주시면 좋겠습니다.
/main/feedback/list,/main/feedback/detail/:id정상 조회/api/persona/save→ SSE 구독)/main/*직접 진입 시/login으로 한 번만 이동하는지체크리스트
기타 사항
requireAccessToken을 켜면서apiInstance·chatInstance는 토큰 없이는 요청 자체가 나가지 않습니다. 이 두 클라이언트로 비인증 호출이 필요한 엔드포인트가 생기면 해당 요청은 로컬에서 막히니, 그때는 옵션을 다시 봐야 합니다. 현재 두 클라이언트의 호출부는 전부/main/*아래라 문제 없습니다.🤖 Generated with Claude Code