-
Notifications
You must be signed in to change notification settings - Fork 0
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
[CAT-69] 디바이스 및 유저 인증 모듈 구현 #29
Conversation
companion object { | ||
const val DEVICE_ID_PREFERENCES_NAME = "device_id_preferences" | ||
private val DEVICE_ID_KEY = stringPreferencesKey("device_id") | ||
} |
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 suspend fun getStoredDeviceId(): String? = try { | ||
dataStore.data | ||
.catch { exception -> | ||
if (exception is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.first()[DEVICE_ID_KEY] | ||
} catch (exception: IOException) { | ||
null | ||
} |
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.
여기 코드에 의도가 궁금해
dataStore 전체를 catch하는데 이때 IO면 null인데 내부에서 IO가 터지면 emptyPreferences
를 반환하는데 IO가 아니면 throw를 하고 있어서 어떤 의도인지 간략하게 알 수 있을까?
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.
하나 찾았다. try - catch
data/src/main/java/com/pomonyang/data/local/datastore/di/DataStoreModule.kt
Outdated
Show resolved
Hide resolved
@Binds | ||
abstract fun provideTokenDataSource(tokenDataSourceImpl: TokenDataSourceImpl): TokenDataSource | ||
|
||
@Binds | ||
abstract fun provideDeviceIdDataSource(deviceIdDataSourceImpl: DeviceIdDataSourceImpl): DeviceIdDataSource | ||
} |
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.
이번에 추가한것들 중에 DataSource나 몇몇 클래스들 Singleton으로 안한 이유가 혹시 있을까?
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.
요거는 제가 놓친 부분인것 같네요 Singleton annotation 추가하기로
data/src/main/java/com/pomonyang/data/remote/interceptor/TokenRefreshInterceptor.kt
Outdated
Show resolved
Hide resolved
data/src/main/java/com/pomonyang/data/remote/model/response/TokenResponse.kt
Show resolved
Hide resolved
data/src/main/java/com/pomonyang/data/remote/di/NetworkModule.kt
Outdated
Show resolved
Hide resolved
@Module | ||
@InstallIn(SingletonComponent::class) |
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.
NetworkModule 클래스에서 전체적으로 정렬이 뭔가 달라진거 같은데 나랑 혹시 옵션이 뭔가 다른건지 아니면 ktlint로 인해서 자동 정렬이 된건지 알 수 있을까?
// 전
fun provideTokenInterceptorRetrofit(
@TokenClient okHttpClient: OkHttpClient,
networkResultCallAdapterFactory: NetworkResultCallAdapterFactory,
json: Json
): Retrofit = Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BASE_URL)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.addCallAdapterFactory(networkResultCallAdapterFactory)
.build()
// 후
fun provideTokenInterceptorRetrofit(
@TokenClient okHttpClient: OkHttpClient,
networkResultCallAdapterFactory: NetworkResultCallAdapterFactory,
json: Json
): Retrofit = Retrofit.Builder().client(okHttpClient).baseUrl(BASE_URL).addConverterFactory(json.asConverterFactory("application/json".toMediaType())).addCallAdapterFactory(networkResultCallAdapterFactory).build()
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.
@Provides
@Singleton
@TokenApi
fun provideTokenInterceptorRetrofit(
@TokenClient okHttpClient: OkHttpClient,
networkResultCallAdapterFactory: NetworkResultCallAdapterFactory,
json: Json
): Retrofit = Retrofit.Builder().client(okHttpClient).baseUrl(BASE_URL).addConverterFactory(json.asConverterFactory("application/json".toMediaType())).addCallAdapterFactory(networkResultCallAdapterFactory).build()
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.
오잉 저도 안스 기준 이렇게 되어있는데 lint로 자동 정렬되어서 올라가나
...c/main/java/com/pomonyang/data/local/datastore/datasource/deviceid/DeviceIdDataSourceImpl.kt
Outdated
Show resolved
Hide resolved
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.
일단은 response,request는 임시로 만들어놨어!
override fun intercept(chain: Interceptor.Chain): Response { | ||
val origin = chain.request() | ||
val response = chain.proceed(origin) | ||
if (response.code == 401) { |
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.
대부분 401롤 처리해줘서 Authenticator 로도 할 수 있지만, 혹시를 대비해서 Interceptor로 만들어봤어요
.newBuilder() | ||
.addHeader("Content-Type", "application/x-www-form-urlencoded") | ||
.addHeader("Accept", "*/*") | ||
.addHeader("Authorization", "Bearer $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.
여기도 나중에 서버 요청에 따라 바꾸는 걸로
...c/main/java/com/pomonyang/data/local/datastore/datasource/deviceid/DeviceIdDataSourceImpl.kt
Outdated
Show resolved
Hide resolved
private suspend fun getStoredDeviceId(): String? = try { | ||
dataStore.data | ||
.catch { exception -> | ||
if (exception is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw exception | ||
} | ||
}.first()[DEVICE_ID_KEY] | ||
} catch (exception: IOException) { | ||
null | ||
} |
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.
@Binds | ||
abstract fun provideTokenDataSource(tokenDataSourceImpl: TokenDataSourceImpl): TokenDataSource | ||
|
||
@Binds | ||
abstract fun provideDeviceIdDataSource(deviceIdDataSourceImpl: DeviceIdDataSourceImpl): DeviceIdDataSource | ||
} |
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.
요거는 제가 놓친 부분인것 같네요 Singleton annotation 추가하기로
@Module | ||
@InstallIn(SingletonComponent::class) |
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.
@Provides
@Singleton
@TokenApi
fun provideTokenInterceptorRetrofit(
@TokenClient okHttpClient: OkHttpClient,
networkResultCallAdapterFactory: NetworkResultCallAdapterFactory,
json: Json
): Retrofit = Retrofit.Builder().client(okHttpClient).baseUrl(BASE_URL).addConverterFactory(json.asConverterFactory("application/json".toMediaType())).addCallAdapterFactory(networkResultCallAdapterFactory).build()
@Module | ||
@InstallIn(SingletonComponent::class) |
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.
오잉 저도 안스 기준 이렇게 되어있는데 lint로 자동 정렬되어서 올라가나
data/src/main/java/com/pomonyang/data/remote/di/NetworkModule.kt
Outdated
Show resolved
Hide resolved
data/src/main/java/com/pomonyang/data/remote/di/NetworkModule.kt
Outdated
Show resolved
Hide resolved
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.
토큰과 관련이 되면서 이것저것 복잡하던 부분 잘 구현된거 같아 고생했어~!
작업 내용
체크리스트
동작 화면
2024-07-23.11.52.32.mov
살려주세요