Skip to content

[Feat/#210] authenticator 도입#211

Open
chanubc wants to merge 6 commits into
developfrom
feat/#210-authenticator
Open

[Feat/#210] authenticator 도입#211
chanubc wants to merge 6 commits into
developfrom
feat/#210-authenticator

Conversation

@chanubc

@chanubc chanubc commented Jul 18, 2025

Copy link
Copy Markdown
Member

✅ 𝗖𝗵𝗲𝗰𝗸-𝗟𝗶𝘀𝘁

  • merge할 브랜치의 위치를 확인해 주세요(main❌/develop⭕)
  • 리뷰가 필요한 경우 리뷰어를 지정해 주세요
  • 리뷰는 (아직 미정)에 진행됩니다.
  • P1 단계의 리뷰는 (아직 미정)까지 반영합니다.
  • Approve된 PR은 assigner가 머지하고, 수정 요청이 온 경우 수정 후 다시 push를 합니다.

📌 𝗜𝘀𝘀𝘂𝗲𝘀

📎𝗪𝗼𝗿𝗸 𝗗𝗲𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻

  • refresh logic autheticator로 분리
  • app restarter 구현

📷 𝗦𝗰𝗿𝗲𝗲𝗻𝘀𝗵𝗼𝘁

💬 𝗧𝗼 𝗥𝗲𝘃𝗶𝗲𝘄𝗲𝗿𝘀

잘 지내셨죠?
Android 15(API 수준 35) -> 이거 하려고 한건데 다른거 했네요
서버가 내려간 것 같아 테스트는 불가..

@chanubc chanubc requested review from hyoeunjoo and yskim6772 July 18, 2025 16:13
@chanubc chanubc self-assigned this Jul 18, 2025
@chanubc chanubc requested a review from Copilot July 18, 2025 16:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a dedicated authenticator pattern to handle token refresh logic and implements an app restart mechanism. The changes separate authentication concerns from the main network interceptor and provide a cleaner architecture for handling authentication failures.

Key changes:

  • Extracted token refresh logic from TokenInterceptor to a dedicated TokenAuthenticator
  • Implemented AppReStarter interface and implementation for app restart functionality
  • Added utility functions for suspend error handling

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
TokenAuthenticator.kt New authenticator handling 401 responses and token refresh logic
TokenInterceptor.kt Simplified to only add authorization headers, removed refresh logic
AppReStarter.kt & DefaultAppReStarter.kt New app restart abstraction with toast functionality
runSuspendCatching.kt Utility function for suspend error handling
RetrofitModule.kt Updated DI configuration to support authenticator pattern
getErrorMessage.kt Added logging for error tracking

?.component
?.let(Intent::makeRestartActivityTask)

context.startActivity(restartIntent)

Copilot AI Jul 18, 2025

Copy link

Choose a reason for hiding this comment

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

The restartIntent could be null if getLaunchIntentForPackage returns null or if the component is null. This will cause a crash when passed to startActivity. Add a null check before calling startActivity.

Suggested change
context.startActivity(restartIntent)
if (restartIntent != null) {
context.startActivity(restartIntent)
} else {
Toast.makeText(context, "Unable to restart the app.", Toast.LENGTH_SHORT).show()
}

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +17
private val scope = CoroutineScope(Dispatchers.Main)

Copilot AI Jul 18, 2025

Copy link

Choose a reason for hiding this comment

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

Creating a CoroutineScope with Dispatchers.Main without proper lifecycle management can lead to memory leaks. Consider using a supervised scope or injecting a properly managed CoroutineScope.

Suggested change
private val scope = CoroutineScope(Dispatchers.Main)
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
fun close() {
scope.cancel()
}

Copilot uses AI. Check for mistakes.
runSuspendCatching {
loginService.postReissueToken(refreshToken)
}.onSuccess {
val newAccess = it.data?.accessToken.orEmpty()

Copilot AI Jul 18, 2025

Copy link

Choose a reason for hiding this comment

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

Using orEmpty() for accessToken means an empty string will be saved and used for authentication if the token is null, which will likely cause authentication failures. Consider returning null or throwing an exception when accessToken is null.

Suggested change
val newAccess = it.data?.accessToken.orEmpty()
val newAccess = it.data?.accessToken ?: return null

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +26
scope.launch {
val restartIntent = context.packageManager
.getLaunchIntentForPackage(context.packageName)
?.component
?.let(Intent::makeRestartActivityTask)

context.startActivity(restartIntent)
}

Copilot AI Jul 18, 2025

Copy link

Choose a reason for hiding this comment

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

The restartApp() method launches a coroutine but doesn't need to be async since startActivity is a synchronous operation. The coroutine launch is unnecessary and could potentially cause timing issues.

Suggested change
scope.launch {
val restartIntent = context.packageManager
.getLaunchIntentForPackage(context.packageName)
?.component
?.let(Intent::makeRestartActivityTask)
context.startActivity(restartIntent)
}
val restartIntent = context.packageManager
.getLaunchIntentForPackage(context.packageName)
?.component
?.let(Intent::makeRestartActivityTask)
context.startActivity(restartIntent)

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +34
scope.launch {
currentToast?.cancel()
currentToast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
currentToast?.show()
}

Copilot AI Jul 18, 2025

Copy link

Choose a reason for hiding this comment

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

The makeToast() method launches a coroutine but doesn't need to be async since Toast operations are already main-thread safe. The coroutine launch is unnecessary.

Suggested change
scope.launch {
currentToast?.cancel()
currentToast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
currentToast?.show()
}
currentToast?.cancel()
currentToast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
currentToast?.show()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] : Authenticator 도입

2 participants