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

Qa/34 로그아웃 후 다른 계정으로 로그인 시, 이전 계정의 데이터가 노출되는 현상 #138

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions data/src/main/java/com/susu/data/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.susu.data

import androidx.datastore.preferences.core.booleanPreferencesKey

object Constants {
const val RETROFIT_TAG = "Retrofit"

private const val SHOW_ONBOARD_VOTE = "Onboarding"
val showOnboardingVoteKey = booleanPreferencesKey(SHOW_ONBOARD_VOTE)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.susu.data.data.repository

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import com.susu.core.model.Token
import com.susu.data.Constants
import com.susu.data.remote.api.AuthService
import com.susu.data.remote.model.request.AccessTokenRequest
import com.susu.data.remote.model.response.toDomain
Expand All @@ -8,12 +13,18 @@ import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
private val authService: AuthService,
private val dataStore: DataStore<Preferences>,
) : LoginRepository {
override suspend fun login(
provider: String,
oauthAccessToken: String,
) = authService.login(
provider = provider,
accessTokenRequest = AccessTokenRequest(oauthAccessToken),
).getOrThrow().toDomain()
): Token {
dataStore.edit { preferences ->
preferences[Constants.showOnboardingVoteKey] = false
}
return authService.login(
provider = provider,
accessTokenRequest = AccessTokenRequest(oauthAccessToken),
).getOrThrow().toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
package com.susu.data.data.repository

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import com.susu.core.model.SignUpUser
import com.susu.core.model.Token
import com.susu.data.Constants.showOnboardingVoteKey
import com.susu.data.remote.api.SignUpService
import com.susu.data.remote.model.request.toData
import com.susu.data.remote.model.response.toDomain
import com.susu.domain.repository.SignUpRepository
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class SignUpRepositoryImpl @Inject constructor(
private val signUpService: SignUpService,
private val dataStore: DataStore<Preferences>,
) : SignUpRepository {

override suspend fun signUp(
provider: String,
oauthAccessToken: String,
signUpUser: SignUpUser,
) = signUpService.signUp(
provider = provider,
accessToken = oauthAccessToken,
user = signUpUser.toData(),
).getOrThrow().toDomain()
): Token {
dataStore.edit { preferences ->
preferences[showOnboardingVoteKey] = false
}
return signUpService.signUp(
provider = provider,
accessToken = oauthAccessToken,
user = signUpUser.toData(),
).getOrThrow().toDomain()
}

override suspend fun canRegister(
provider: String,
Expand All @@ -30,4 +43,10 @@ class SignUpRepositoryImpl @Inject constructor(
accessToken = oauthAccessToken,
).getOrThrow().canRegister
}

override suspend fun getShowOnboardVote(): Boolean? {
return dataStore.data.map { preferences ->
preferences[showOnboardingVoteKey]
}.firstOrNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import com.susu.core.model.User
import com.susu.core.model.exception.UserNotFoundException
import com.susu.data.Constants.showOnboardingVoteKey
import com.susu.data.remote.api.AuthService
import com.susu.data.remote.api.UserService
import com.susu.data.remote.model.request.UserPatchRequest
Expand Down Expand Up @@ -63,6 +64,7 @@ class UserRepositoryImpl @Inject constructor(
override suspend fun withdraw() {
dataStore.edit { preferences ->
preferences.remove(userKey)
preferences.remove(showOnboardingVoteKey)
}
authService.withdraw().getOrThrow()
}
Expand Down
5 changes: 0 additions & 5 deletions data/src/main/java/com/susu/data/remote/Constants.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.susu.data.remote.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.susu.data.remote.Constants.RETROFIT_TAG
import com.susu.data.Constants.RETROFIT_TAG
import com.susu.data.remote.network.TokenAuthenticator
import com.susu.data.remote.network.TokenInterceptor
import com.susu.data.remote.retrofit.ResultCallAdapterFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import com.susu.core.model.Token
interface SignUpRepository {
suspend fun signUp(provider: String, oauthAccessToken: String, signUpUser: SignUpUser): Token
suspend fun canRegister(provider: String, oauthAccessToken: String): Boolean
suspend fun getShowOnboardVote(): Boolean?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.susu.domain.usecase.loginsignup

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.domain.repository.SignUpRepository
import javax.inject.Inject

class CheckShowOnboardVoteUseCase @Inject constructor(
private val signUpRepository: SignUpRepository,
) {
suspend operator fun invoke() = runCatchingIgnoreCancelled {
signUpRepository.getShowOnboardVote()
}.getOrNull()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.susu.feature.loginsignup.social

import android.content.Context
import com.kakao.sdk.auth.AuthApiClient
import com.kakao.sdk.auth.TokenManagerProvider
import com.kakao.sdk.common.model.AuthError
import com.kakao.sdk.common.model.ClientError
Expand All @@ -10,8 +9,6 @@ import com.kakao.sdk.user.UserApiClient
import timber.log.Timber

object KakaoLoginHelper {
val hasKakaoLoginHistory
get() = AuthApiClient.instance.hasToken()

fun login(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import com.susu.feature.mypage.main.component.MyPageMenuItem
fun MyPageDefaultRoute(
padding: PaddingValues,
viewModel: MyPageViewModel = hiltViewModel(),
navigateToLogin: () -> Unit,
restartMainActivity: () -> Unit,
navigateToInfo: () -> Unit,
navigateToSocial: () -> Unit,
navigateToPrivacyPolicy: () -> Unit,
Expand All @@ -77,7 +77,7 @@ fun MyPageDefaultRoute(

viewModel.sideEffect.collectWithLifecycle { sideEffect ->
when (sideEffect) {
MyPageEffect.NavigateToLogin -> navigateToLogin()
MyPageEffect.NavigateToLogin -> restartMainActivity()
MyPageEffect.NavigateToInfo -> navigateToInfo()
MyPageEffect.NavigateToSocial -> navigateToSocial()
is MyPageEffect.ShowSnackbar -> onShowSnackbar(SnackbarToken(message = sideEffect.msg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun NavController.navigateMyPagePrivacyPolicy() {

fun NavGraphBuilder.myPageNavGraph(
padding: PaddingValues,
navigateToLogin: () -> Unit,
restartMainActivity: () -> Unit,
navigateToInfo: () -> Unit,
navigateToSocial: () -> Unit,
navigateToPrivacyPolicy: () -> Unit,
Expand All @@ -42,7 +42,7 @@ fun NavGraphBuilder.myPageNavGraph(
composable(route = MyPageRoute.defaultRoute) {
MyPageDefaultRoute(
padding = padding,
navigateToLogin = navigateToLogin,
restartMainActivity = restartMainActivity,
navigateToInfo = navigateToInfo,
navigateToSocial = navigateToSocial,
navigateToPrivacyPolicy = navigateToPrivacyPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class MainActivity : ComponentActivity() {
if (uiState.isNavigating) {
KakaoLoginHelper.getAccessToken { accessToken ->
viewModel.navigate(
hasKakaoLoginHistory = KakaoLoginHelper.hasKakaoLoginHistory,
kakaoAccessToken = accessToken,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.susu.feature.navigator

import android.content.Intent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
Expand Down Expand Up @@ -226,7 +227,12 @@ internal fun MainScreen(

myPageNavGraph(
padding = innerPadding,
navigateToLogin = navigator::navigateLogin,
restartMainActivity = {
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
context.startActivity(intent)
},
navigateToInfo = navigator::navigateMyPageInfo,
navigateToSocial = navigator::navigateMyPageSocial,
navigateToPrivacyPolicy = navigator::navigateMyPagePrivacyPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.susu.core.ui.SnsProviders
import com.susu.core.ui.base.BaseViewModel
import com.susu.domain.usecase.categoryconfig.GetCategoryConfigUseCase
import com.susu.domain.usecase.loginsignup.CheckCanRegisterUseCase
import com.susu.domain.usecase.loginsignup.CheckShowOnboardVoteUseCase
import com.susu.domain.usecase.loginsignup.LoginUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
Expand All @@ -22,6 +23,7 @@ import javax.inject.Inject
class MainViewModel @Inject constructor(
private val loginUseCase: LoginUseCase,
private val checkCanRegisterUseCase: CheckCanRegisterUseCase,
private val checkShowOnboardVoteUseCase: CheckShowOnboardVoteUseCase,
private val getCategoryConfigUseCase: GetCategoryConfigUseCase,
) : BaseViewModel<MainState, MainSideEffect>(MainState()) {
companion object {
Expand Down Expand Up @@ -59,8 +61,8 @@ class MainViewModel @Inject constructor(
intent { copy(isInitializing = false) }
}

fun navigate(hasKakaoLoginHistory: Boolean, kakaoAccessToken: String?) = viewModelScope.launch {
if (hasKakaoLoginHistory.not()) {
fun navigate(kakaoAccessToken: String?) = viewModelScope.launch {
if (checkShowOnboardVoteUseCase() == null) {
intent { copy(isNavigating = false) }
return@launch
}
Expand Down
Loading