-
Notifications
You must be signed in to change notification settings - Fork 1
[#293] 토큰 재발급 로직 리팩토링 #294
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
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.
Summary of Changes
Hello @Hrepay, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refactors the token reissuance mechanism to enhance robustness and user experience. It introduces a new Swift Concurrency-based approach for handling token refreshes, centralizing the logic and preventing race conditions. The changes also include proactive token expiration checks and improved error handling for session management.
Highlights
- Token Reissuance Refactor: The token reissuance logic has been completely overhauled, moving from a Moya-based
reissueProviderto a new Swift Concurrency-based system. This improves asynchronous handling and reliability. - Centralized Token Refresh: New
TokenRefresherandTokenManagerclasses are introduced.TokenRefresherhandles the actual API call for reissuing tokens, whileTokenManagermanages token expiration checks and triggers refreshes. - Enhanced Auth Interceptor: The
AuthInterceptornow correctly handles both 401 (Unauthorized) and 403 (Forbidden) HTTP status codes to trigger token reissuance attempts, addressing a previously missing exception. - Proactive Token Management: The
TokenManagernow proactively checks for access token expiration (if less than 2 hours remaining) by decoding the JWT payload. This reissuance is automatically triggered on app launch and when the app enters the foreground. - Improved User Feedback: The toast message for session expiration has been updated from a generic "System error" to a more specific "Session expired. Please log in again." in relevant view controllers.
- Configurable Logging: The network logging system has been refined with a new
isVerboseNetworkLoggingEnabledflag, allowing developers to easily control the verbosity of network logs during development. - Swift Concurrency Support: The project settings have been updated to explicitly enable
SWIFT_CONCURRENCY: "complete", ensuring full support for the new concurrency model.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The code changes introduce a refactored token reissue logic using Swift Concurrency, improving thread safety and code structure with separate TokenManager and TokenRefresher components. The AuthInterceptor automatically attaches access tokens to network requests and handles token reissuance upon authentication failures.
| do { | ||
| try await TokenRefresher.shared.refreshIfNeeded() | ||
| await MainActor.run { completion(.retry) } | ||
| } catch { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| /// refreshToken 기반으로 accessToken 재발급 요청 | ||
| private func performReissuance() async throws -> SignResponse { | ||
| try await withCheckedThrowingContinuation { continuation in | ||
| let provider = MoyaProvider<ReissueRouter>() |
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.
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.
이건 좋은 것 같아서 채택했습니다!
제 의견은 단순히 메뉴 확인용으로 앱을 사용하는 경우도 많은 것 같아 토큰이 필요없는 경우라면 굳이 로그인하지 않아도 될 것 같습니다. 해당 부분도 안드와 통일하면 좋을 것 같은데 어떻게 생각하시나요?! @kangyuri1114 @HI-JIN2 |
|
@CJiu01 안드도 아요처럼 현재 토큰이 만료 시에 바로 로그인 화면 이동이 아니라 |
CJiu01
left a comment
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.
Concurrency를 아주 야무지게 사용하셨군요! 수고하셨습니다!!
홈 화면은 인증 없이 접근 가능하기 때문에 앱 실행 직후 로그인 창으로 전환되지 않고 정상 진입 -> 해당 상황은 사용자가 앱을 완전히 종료하지 않은 상태(백그라운드 상태)에서 앱 접속하는 경우에 발생하는거죠?
| defer { | ||
| isRefreshing = false | ||
| } |
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.
defer 사용해서 강제할 수도 있군요!
| accessToken: data.accessToken, | ||
| refreshToken: data.refreshToken | ||
| ) | ||
| print("⭐️⭐️ 재발급 완료 ⭐️⭐️ – 새 accessToken:", data.accessToken) |
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.
해당 부분은 디버그환경일 때만 찍어주면 좋을듯요!
| /// 네트워크 로그 출력을 제어하는 플래그 | ||
| private let isVerboseNetworkLoggingEnabled = false |
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.
로그 출력할 때, 해당 부분을 true로 사용하면 되나요?
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.
넵 true로 바꾸면 다시 원래대로 찍힙니다!
넵 맞습니다! |
#296 테스트 해보니 탈퇴 이후 별도 액션 없이 화면이 바뀌는 게 약간 튕기는 듯한 느낌이 들어서, 토스트 메시지까지 추가하고 해당 작업까지 업데이트 올리려 합니다! 제가 해당 작업 후, 업데이트 진행하겠습니다! |
#️⃣ 관련 이슈
Resolved #293
💡작업 내용
💬리뷰 요구사항(선택)
현재 로직은 토큰 관련 로직 다음과 같습니다.
하지만 방학에는 장기간 앱을 사용하지 않을 사용자도 있을텐데 그렇게 되면 refresh token도 만료될 수 있습니다.
이 경우, 홈 화면은 인증 없이 접근 가능하기 때문에 앱 실행 직후 로그인 창으로 전환되지 않고 정상 진입합니다.
팀원 분들의 의견이 궁금합니다.
작업 내용 중에도 수정사항이 있다면 말씀해주세요!