Skip to content

기본 정보 입력시 api 연결#43

Closed
stellarbg wants to merge 1 commit intodevelopfrom
feature/#4-기본정보입력-api연결

Hidden character warning

The head ref may contain hidden characters: "feature/#4-\uae30\ubcf8\uc815\ubcf4\uc785\ub825-api\uc5f0\uacb0"
Closed

기본 정보 입력시 api 연결#43
stellarbg wants to merge 1 commit intodevelopfrom
feature/#4-기본정보입력-api연결

Conversation

@stellarbg
Copy link
Collaborator

#️⃣ 이슈 번호

🖥️ 작업 내용

  • 기본 정보 입력시 api 연결

ℹ️ 참고 사항

@stellarbg stellarbg added the 리뷰 요청 pr: 리뷰어에게 리뷰 요청 상태 label Jan 12, 2025
@stellarbg stellarbg self-assigned this Jan 12, 2025
finalGenderValid.value = isValid
}

suspend fun onboardingJoin(onboardingDto: OnboardingDto) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ViewModel 에서 domain 에 선언된 OnboardingDto 타입을 매개변수로 해도 되는지
아니면, LoginVo 타입처럼 하면 좋은지 궁금합니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

domain에서 사용하려는 model이기 때문에 dto를 사용해도 괜찮을 것 같아요!

다만 OnboardingDto를 Activity에서 선언해서 ViewModel로 넘겨주기 보다는 viewModel의 onboardingJoin 함수의 파라미터로 nickname, birthDate, gender를 받아서 ViewModel에서 OnboardingDto 객체를 만들어주는게 좋을 것 같아요!

그리고 Activity에서 lifecycleScope를 사용하는 것보다 ViewModel의 lifecycle에 맞게 작업을 수행하기 위해 ViewModel에서 viewModelScope를 사용하는게 좋을 것 같습니다.

다른 리뷰 사항들은 별도 코멘트로 추가할게요!

Copy link
Contributor

Choose a reason for hiding this comment

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

LoginViewModel의 kakaoLogin, googleLogin은 제가 함수의 결과 값을 사용하기 위해 Activity의 lifecycleScope 내에서 네트워크 통신 함수를 호출했는데 이 부분도 지금 생각해보면 수정이 필요할 것 같네요..! 이 부분은 추후에 제가 수정하겠습니다!

/** 온보딩 */
@PUT("auth/join")
suspend fun onboardingJoin(
@Header("Authorization") accessToken: String,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Header("Authorization") accessToken: String
매번 api 호출 할때마다 토큰값을 받아오는 것 보다 NetworkModule 파일에서 인터셉터로 헤더에 Authorization 헤더를 자동으로 추가할려고 했는데요

authLocalDataSource.getAccessToken() 을 통해서 토큰값을 가지고 올려고 했는데
Suspend function 'getAccessToken' should be called only from a coroutine or another suspend function

이런 오류가 생겨서 SharedPreferences 파일에 있는 토큰값을 가지고 올려고 했는데 암호화가 되어있어서 어떻게 하는게 좋을까요??

Copy link
Contributor

@imaec imaec Jan 12, 2025

Choose a reason for hiding this comment

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

말씀하신대로 Interceptor에서 AccessToken을 가져와서 api를 호출하는게 좋을 것 같아요!
제가 authLocalDataSource.getAccessToken() 함수를 suspend 함수로 만들었는데 sharedPreferences에서 값을 가져오는 건 비동기로 동작할 필요가 없어서 suspend 키워드를 삭제하고 사용하면 될 것 같아요!

예를 들어서

AuthLocalDataSource

interface AuthLocalDataSource {

    fun saveAccessToken(accessToken: String)

    fun saveRefreshToken(refreshToken: String)

    fun getAccessToken(): String

    fun getRefreshToken(): String

    fun removeToken()
}

TokenInterceptor(info.imdang.data.interceptor)

class TokenInterceptor(private val authLocalDataSource: AuthLocalDataSource) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val accessToken = authLocalDataSource.getAccessToken()

        return chain.proceed(
            chain
                .request()
                .newBuilder()
                .addHeader("Authorization", "Bearer $accessToken")
                .url(chain.request().url)
                .build()
        )
    }
}

NetworkModule

    @Provides
    @Singleton
    fun providesTokenInterceptor(
        authLocalDataSource: AuthLocalDataSource
    ): TokenInterceptor = TokenInterceptor(authLocalDataSource)

   ...

    @Provides
    @Singleton
    @Named("imdang")
    fun providesOkHttpClient(
        tokenInterceptor: TokenInterceptor,
        httpLoggingInterceptor: HttpLoggingInterceptor
    ): OkHttpClient {
        return OkHttpClient
            .Builder()
            .addInterceptor(tokenInterceptor)
            .addInterceptor(httpLoggingInterceptor)
            .build()
    }

와 같이 코드를 작성하면 api 호출 마다 Header에 AccessToken을 넣어줄 수 있을 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

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

@wjdwntjd55 Header에 AccessToken을 설정할 때 Bearer 키워드를 추가해줘야 할 것 같습니다!
참고 부탁드려요!

@imaec imaec added 리뷰 확인 pr: 리뷰 작성 후 담당자 확인 상태 and removed 리뷰 요청 pr: 리뷰어에게 리뷰 요청 상태 labels Jan 12, 2025
@stellarbg stellarbg closed this Jan 14, 2025
@imaec imaec deleted the feature/#4-기본정보입력-api연결 branch January 16, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

리뷰 확인 pr: 리뷰 작성 후 담당자 확인 상태

Projects

None yet

Development

Successfully merging this pull request may close these issues.

기본정보입력 & 가입 완료 구현

2 participants