Skip to content
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

개선된 로그인 반영 (Oauth) #396

Merged
merged 12 commits into from
Feb 13, 2024
Merged

개선된 로그인 반영 (Oauth) #396

merged 12 commits into from
Feb 13, 2024

Conversation

2taezeat
Copy link
Collaborator

@2taezeat 2taezeat commented Feb 1, 2024

Issue

Overview

  • LoginResponse 변경 => AuthTokenResponse
  • errorCode 추가
  • domain AuthToken model 추가 및 반영
  • UserTokenRepository삭제 및, TokenDataSource이 UserTokenRepository 기능을 대체
  • auth 에러 (인증 에러, 401) 일때, refreshToken() 호출

@2taezeat 2taezeat added ✨ feat 기능 개발 🤖 android android labels Feb 1, 2024
@2taezeat 2taezeat self-assigned this Feb 1, 2024
@2taezeat 2taezeat modified the milestones: 🔎 search, 📝 login Feb 1, 2024
Copy link

github-actions bot commented Feb 1, 2024

Test Results

6 tests   6 ✅  1s ⏱️
2 suites  0 💤
2 files    0 ❌

Results for commit 8b9bd0c.

♻️ This comment has been updated with latest results.

@2taezeat 2taezeat marked this pull request as ready for review February 13, 2024 10:44
Comment on lines 105 to 112
if (errorResponse.statusCode == 401) {
throw CtException(errorResponse.message, CtErrorType.UN_AUTHORIZED)
val newAccessToken = runBlocking {
val authTokenResponse = authRepository.get().refreshToken()
authTokenResponse.first().accessToken
}
val newRequest = originalRequest.putTokenHeader(newAccessToken)
chain.proceed(newRequest)
}
Copy link
Member

Choose a reason for hiding this comment

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

이 부분 로직은 retrofit의 authenticator를 이용해서 구현할 수도 있어.

@@ -87,16 +91,24 @@ object NetworkModule {
@ErrorInterceptor
@Singleton
@Provides
fun provideErrorInterceptor(): Interceptor {
fun provideErrorInterceptor(
authRepository: Lazy<AuthRepository>
Copy link
Member

Choose a reason for hiding this comment

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

  1. 혹시 Lazy인 이유가 있을까?
  2. repository는 데이터 모듈을 추상화하는 역할이라, 데이터 모듈 내부적으로는 repository 안 거치고 바로 data에 접근하는 것도 가능해
  3. 데이터 모듈은 interceptor ← Api(or DataStore) ← repository 이런 구조인데 interceptor가 다시 repository를 참조하면 순환 참조가 일어나는데 주의가 필요할 것 같아

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lazy 인 이유는 말씀하신, 3번 처럼 cycle이 일어나는 것 때문에 사용하였습니다.
더 개선할 수 있을거 같은데, 이슈로 따로 빼서 해보겠습니다~�

<참고>

return Interceptor { chain ->
try {
val response = chain.proceed(chain.request())
val originalRequest = chain.request()
val response = chain.proceed(originalRequest)
if (response.isSuccessful) return@Interceptor response
val errorString = response.body?.string()
val errorResponse = Json.decodeFromString<ErrorResponse>(errorString ?: "")

if (errorResponse.statusCode == 401) {
Copy link
Member

Choose a reason for hiding this comment

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

코드를 자세히 보진 않았는데, 원래 로그인 시도할 때 LoginViewModel에서 401을 받으면 회원가입(닉네임) 화면으로 이동했던 걸로 기억하는데, 이렇게 변경했을 때도 로그인했을 때 미가입 회원일 경우 회원가입 화면으로 잘 이동하는지 확인해 주세용
이 코드가 이상하다기보다는, 기존의 회원가입 여부 처리 방식의 문제라고 생각하긴 해

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://www.notion.so/2024-01-29-refresh-9dbaae6a05f3448ca0294ecbafeba23c 참고하여 개발하였습니다.

참고하여 테스트 해보겠습니다~

@2taezeat 2taezeat merged commit e1b8652 into develop Feb 13, 2024
2 checks passed
@2taezeat 2taezeat deleted the android/feature/394 branch February 13, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android android ✨ feat 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

개선된 로그인 반영 (Oauth)
2 participants