Skip to content

fix: 네트워크 버그 수정#101

Merged
clxxrlove merged 3 commits into
developfrom
BOOK-128-fix/#76
Jul 22, 2025
Merged

fix: 네트워크 버그 수정#101
clxxrlove merged 3 commits into
developfrom
BOOK-128-fix/#76

Conversation

@clxxrlove
Copy link
Copy Markdown
Member

@clxxrlove clxxrlove commented Jul 21, 2025

🔗 관련 이슈

📘 작업 유형

  • ✨ Feature (기능 추가)
  • 🐞 Bugfix (버그 수정)
  • 🔧 Refactor (코드 리팩토링)
  • ⚙️ Chore (환경 설정)
  • 📝 Docs (문서 작성 및 수정)
  • ✅ Test (기능 테스트)
  • 🎨 style (코드 스타일 수정)

📙 작업 내역

  • 확인되지 않은 특정 상황에서 인증에 실패하는 현상 수정
    • 네트워크 로그 확인 결과 (Pulse) 기존 요청 실패 이후 Refresh에는 성공하지만, 다음 요청이 계속 실패함
    • 이 때, 첫 요청과 Refresh 요청 이후의 AccessToken이 같은 것을 확인 -> clear가 빠진 것을 확인

🧪 테스트 내역

  • 브라우저/기기에서 동작 확인
  • 엣지 케이스 테스트 완료
  • 기존 기능 영향 없음

💬 추가 설명 or 리뷰 포인트 (선택)

  • 다시 문제가 발생해서 이슈 재오픈하고 작업했습니다

Summary by CodeRabbit

  • 버그 수정

    • 토큰 저장 또는 갱신 후 토큰 캐시가 즉시 초기화되어 인증 관련 동작의 일관성이 향상되었습니다.
  • 리팩터링

    • 인증 토큰 만료(401) 시 토큰을 새로고침하고 요청을 한 번 재시도하는 방식으로 인증 재시도 로직이 단순화되었습니다.
    • 내부 코드 구조가 개선되어 유지보수가 용이해졌습니다.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 21, 2025

Walkthrough

이 변경 사항은 인증 토큰 저장 후 tokenProvider의 캐시를 즉시 비우는 로직을 로그인 및 토큰 갱신 과정에 추가하였으며, 네트워크 요청의 401(Unauthorized) 응답 시 토큰을 새로고침하고 재시도하는 리트라이 로직을 보다 명시적으로 단순화하였습니다. 또한, 일부 접근 제어자를 수정하였고, 코드 포맷팅 변경이 포함되었습니다.

Changes

파일/경로 요약 변경 요약
src/Projects/BKData/Sources/Repository/DefaultAuthRepository.swift 로그인 시 토큰 저장 후 tokenProvider.clearCache() 호출을 추가하여 캐시를 즉시 비움.
src/Projects/BKNetwork/Sources/NetworkAssembly.swift 토큰 갱신 후 tokenProvider.clearCache()를 호출하는 사이드 이펙트 추가.
src/Projects/BKNetwork/Sources/Provider/OAuthNetworkProvider.swift 401 응답 시 토큰 새로고침 후 요청을 재시도하는 로직으로 리트라이 방식을 명시적으로 단순화 및 리팩토링.
src/Projects/BKNetwork/Sources/Helper/AuthRetrier.swift AuthRetrier의 extension 접근 제어자를 private에서 공개로 변경.
src/Projects/BKStorage/Sources/TokenStorage/KeychainTokenProvider.swift 초기화 메서드 이후에 공백 한 줄 추가(포맷팅 변경).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OAuthNetworkProvider
    participant AuthRetrier
    participant TokenProvider

    Client->>OAuthNetworkProvider: request(target, type)
    OAuthNetworkProvider->>OAuthNetworkProvider: makeRequest
    OAuthNetworkProvider->>Client: 응답 (성공 시)
    alt 401 Unauthorized 응답
        OAuthNetworkProvider->>AuthRetrier: performRefresh()
        AuthRetrier->>TokenProvider: 토큰 새로고침 및 저장
        TokenProvider->>TokenProvider: clearCache()
        AuthRetrier-->>OAuthNetworkProvider: 새 토큰 반환
        OAuthNetworkProvider->>OAuthNetworkProvider: makeRequest (재시도)
        OAuthNetworkProvider->>Client: 응답 (성공/실패)
    end
Loading

Estimated code review effort

2 (~15분)

Possibly related PRs

Suggested labels

🐞 fix

Suggested reviewers

  • doyeonk429

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a11976b and dcacb60.

📒 Files selected for processing (5)
  • src/Projects/BKData/Sources/Repository/DefaultAuthRepository.swift (1 hunks)
  • src/Projects/BKNetwork/Sources/Helper/AuthRetrier.swift (1 hunks)
  • src/Projects/BKNetwork/Sources/NetworkAssembly.swift (1 hunks)
  • src/Projects/BKNetwork/Sources/Provider/OAuthNetworkProvider.swift (1 hunks)
  • src/Projects/BKStorage/Sources/TokenStorage/KeychainTokenProvider.swift (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: clxxrlove
PR: YAPP-Github/Reed-iOS#94
File: src/Projects/BKData/Sources/Repository/DefaultBookRepository.swift:15-40
Timestamp: 2025-07-21T05:16:18.481Z
Learning: clxxrlove는 Reed-iOS 프로젝트에서 기능 구현 시 우선순위를 명확하게 설정한다. 기본 기능 구현을 먼저 완료하고, 에러 처리나 안정성 개선은 이후 단계에서 진행하는 것을 선호한다.
Learnt from: clxxrlove
PR: YAPP-Github/Reed-iOS#94
File: src/Projects/BKData/Sources/API/BookAPI.swift:51-58
Timestamp: 2025-07-20T08:11:52.850Z
Learning: Reed-iOS 프로젝트에서 clxxrlove는 미구현 기능의 경우 API 구조를 먼저 정의하고 실제 구현은 나중에 하는 단계적 개발 방식을 사용한다. upsert 같은 기능에서 body가 nil로 설정되어 있어도 이는 의도적인 것일 수 있다.
Learnt from: clxxrlove
PR: YAPP-Github/Reed-iOS#69
File: src/Projects/BKDesign/PreviewApp/Sources/View/CatalogViewController.swift:57-70
Timestamp: 2025-07-10T14:01:04.933Z
Learning: clxxrlove는 Reed-iOS 프로젝트에서 테스트/데모용 코드와 프로덕션 코드에 대해 다른 코드 품질 기준을 적용한다. 테스트용 뷰에서는 안전성 검증 등의 엄격한 코드 품질 요구사항을 적용하지 않는 것을 선호한다.
Learnt from: clxxrlove
PR: YAPP-Github/Reed-iOS#56
File: src/Projects/BKPresentation/Sources/Constant/PresentationKeys.swift:3-5
Timestamp: 2025-07-07T13:53:13.006Z
Learning: clxxrlove prefers using enum over struct for constants namespace due to better runtime performance, memory layout, and compiler optimizations. Enum prevents instantiation at compile time without needing private init().
src/Projects/BKNetwork/Sources/Helper/AuthRetrier.swift (1)

Learnt from: clxxrlove
PR: #56
File: src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift:109-111
Timestamp: 2025-07-07T13:47:32.784Z
Learning: The LoginViewModel's authenticateWithToken case in src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift is test code and not important for implementation according to the user.

src/Projects/BKData/Sources/Repository/DefaultAuthRepository.swift (2)

Learnt from: clxxrlove
PR: #56
File: src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift:109-111
Timestamp: 2025-07-07T13:47:32.784Z
Learning: The LoginViewModel's authenticateWithToken case in src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift is test code and not important for implementation according to the user.

Learnt from: clxxrlove
PR: #66
File: src/Projects/BKData/Sources/DataAssembly.swift:49-60
Timestamp: 2025-07-09T02:32:03.801Z
Learning: clxxrlove prefers separating protocol registrations for RefreshHandler and AuthRepository even when using the same implementation (DefaultAuthRepository) to maintain Interface Segregation Principle, where RefreshHandler focuses on token refresh and AuthRepository handles broader authentication operations.

src/Projects/BKNetwork/Sources/NetworkAssembly.swift (2)

Learnt from: clxxrlove
PR: #66
File: src/Projects/BKData/Sources/DataAssembly.swift:49-60
Timestamp: 2025-07-09T02:32:03.801Z
Learning: clxxrlove prefers separating protocol registrations for RefreshHandler and AuthRepository even when using the same implementation (DefaultAuthRepository) to maintain Interface Segregation Principle, where RefreshHandler focuses on token refresh and AuthRepository handles broader authentication operations.

Learnt from: clxxrlove
PR: #56
File: src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift:109-111
Timestamp: 2025-07-07T13:47:32.784Z
Learning: The LoginViewModel's authenticateWithToken case in src/Projects/BKPresentation/Sources/AuthFlow/ViewModel/LoginViewModel.swift is test code and not important for implementation according to the user.

src/Projects/BKNetwork/Sources/Provider/OAuthNetworkProvider.swift (1)

Learnt from: clxxrlove
PR: #79
File: src/Projects/BKPresentation/Sources/MainFlow/Setting/ViewModel/SettingViewModel.swift:78-85
Timestamp: 2025-07-11T12:12:48.911Z
Learning: AppVersionUseCase.execute() returns AnyPublisher<String, Never> where the Failure type is Never, making error handling unnecessary. The app version is retrieved from the main bundle which is always available, and the implementation already handles missing version by defaulting to "-".

🧬 Code Graph Analysis (2)
src/Projects/BKData/Sources/Repository/DefaultAuthRepository.swift (1)
src/Projects/BKStorage/Sources/TokenStorage/KeychainTokenProvider.swift (1)
  • clearCache (44-47)
src/Projects/BKNetwork/Sources/NetworkAssembly.swift (1)
src/Projects/BKStorage/Sources/TokenStorage/KeychainTokenProvider.swift (1)
  • clearCache (44-47)
🔇 Additional comments (7)
src/Projects/BKStorage/Sources/TokenStorage/KeychainTokenProvider.swift (1)

15-15: 코드 포매팅 개선이 적절합니다.

초기화 메서드 이후 빈 줄 추가로 가독성이 향상되었습니다.

src/Projects/BKData/Sources/Repository/DefaultAuthRepository.swift (1)

45-47: 로그인 후 토큰 캐시 정리가 올바르게 구현되었습니다.

토큰 저장 성공 후 즉시 tokenProvider.clearCache()를 호출하여 PR 목표에서 언급한 AccessToken이 갱신되지 않는 버그를 해결했습니다.

src/Projects/BKNetwork/Sources/Helper/AuthRetrier.swift (1)

34-34: 접근 제어자 변경이 적절합니다.

AuthRetrier 확장의 private 접근 제어자를 제거하여 OAuthNetworkProvider에서 shouldRetryperformRefresh 메서드를 사용할 수 있게 되었습니다. 새로운 재시도 로직 구현을 위한 필요한 변경입니다.

src/Projects/BKNetwork/Sources/NetworkAssembly.swift (1)

41-43: 토큰 갱신 시 캐시 정리가 올바르게 구현되었습니다.

refreshHandler에서 토큰 저장 성공 후 tokenProvider.clearCache()를 호출하여 토큰 갱신 프로세스에서의 캐시 일관성을 보장합니다. DefaultAuthRepository의 로그인 메서드와 동일한 패턴을 사용하여 일관성 있는 구현입니다.

src/Projects/BKNetwork/Sources/Provider/OAuthNetworkProvider.swift (3)

28-28: 재시도 로직 리팩토링이 적절합니다.

기존의 makeRequest 직접 호출을 requestWithRetry로 변경하여 재시도 로직이 명시적으로 처리되도록 개선했습니다.


39-51: 새로운 요청-재시도 패턴이 명확합니다.

requestWithRetry 메서드가 요청 후 재시도 로직을 명시적으로 처리하여 코드 가독성과 유지보수성이 향상되었습니다.


53-71: 401 응답 처리 로직이 명확하고 직관적입니다.

기존의 복잡한 재시도 핸들링을 401 상태코드 명시적 확인과 authRetrier.performRefresh() 직접 호출로 단순화했습니다. 이는 PR 목표에서 언급한 인증 실패 후 재시도 버그를 명확하게 해결합니다.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BOOK-128-fix/#76

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @coderabbitai 요약 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@doyeonk429 doyeonk429 added the 🐞 fix Something isn't working label Jul 21, 2025
@github-actions github-actions Bot requested a review from doyeonk429 July 21, 2025 16:46
Copy link
Copy Markdown
Member

@doyeonk429 doyeonk429 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear 문제 였군요... ! 좋습니다 👍

@clxxrlove clxxrlove merged commit 2e6818d into develop Jul 22, 2025
5 checks passed
@clxxrlove clxxrlove deleted the BOOK-128-fix/#76 branch July 22, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 fix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BOOK-128/fix] 네트워크 버그 수정

2 participants