Skip to content

Commit

Permalink
#71 Feat : 로그아웃이나 회원탈퇴 시 소셜 로그인 계정 로그아웃
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Mar 30, 2024
1 parent d92c249 commit ec278ef
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
applicationId = "com.teamwiney.winey"
minSdk = 24
targetSdk = 34
versionCode = 1
versionCode = 2
versionName = "1.0"

signingConfig = signingConfigs.getByName("debug")
Expand Down
3 changes: 3 additions & 0 deletions feature/mypage/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ dependencies {
implementation(libs.bundles.hilt.navigation)
implementation(libs.lifecycle.runtime.compose)
implementation(libs.datastore)

implementation(libs.kakao.sdk.user)
implementation(libs.play.services.auth)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.teamwiney.mypage

import android.app.Activity
import androidx.lifecycle.viewModelScope
import androidx.navigation.navOptions
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.kakao.sdk.user.UserApiClient
import com.teamwiney.core.common.base.BaseViewModel
import com.teamwiney.core.common.navigation.AuthDestinations
import com.teamwiney.core.common.navigation.HomeDestinations
Expand Down Expand Up @@ -209,7 +213,7 @@ class MyPageViewModel @Inject constructor(
}
}

fun withdrawal() = viewModelScope.launch {
fun withdrawal(activity: Activity) = viewModelScope.launch {
val userId = runBlocking { dataStoreRepository.getIntValue(USER_ID).first() }
val reason = if (currentState.isWithdrawalReasonDirectInput) {
currentState.withdrawalReasonDirectInput
Expand All @@ -223,6 +227,20 @@ class MyPageViewModel @Inject constructor(
updateState(currentState.copy(isLoading = false))
when (it) {
is ApiResult.Success -> {
val googleSignInClient = GoogleSignIn.getClient(
activity,
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build()
)
googleSignInClient.signOut()

UserApiClient.instance.logout { error ->
if (error != null) {
postEffect(
MyPageContract.Effect.ShowSnackBar("${error.message}")
)
}
}

dataStoreRepository.deleteStringValue(ACCESS_TOKEN)
dataStoreRepository.deleteStringValue(REFRESH_TOKEN)
postEffect(
Expand Down Expand Up @@ -276,7 +294,7 @@ class MyPageViewModel @Inject constructor(
}
}

fun logOut() = viewModelScope.launch {
fun logOut(activity: Activity) = viewModelScope.launch {
val deviceId = runBlocking { dataStoreRepository.getStringValue(DEVICE_ID).first() }

authRepository.logOut(deviceId).onStart {
Expand All @@ -285,6 +303,20 @@ class MyPageViewModel @Inject constructor(
updateState(currentState.copy(isLoading = false))
when (it) {
is ApiResult.Success -> {
val googleSignInClient = GoogleSignIn.getClient(
activity,
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build()
)
googleSignInClient.signOut()

UserApiClient.instance.logout { error ->
if (error != null) {
postEffect(
MyPageContract.Effect.ShowSnackBar("${error.message}")
)
}
}

postEffect(MyPageContract.Effect.NavigateTo(
AuthDestinations.Login.ROUTE, navOptions = navOptions {
popUpTo(HomeDestinations.ROUTE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teamwiney.mypage.account

import android.app.Activity
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -20,6 +21,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
Expand All @@ -43,6 +45,7 @@ fun MyPageAccountScreen(
bottomSheetState: WineyBottomSheetState
) {
val effectFlow = viewModel.effect
val activity = LocalContext.current as Activity

BackHandler {
if (bottomSheetState.bottomSheetState.isVisible) {
Expand Down Expand Up @@ -70,7 +73,7 @@ fun MyPageAccountScreen(
MyPageLogOutBottomSheet(
onConfirm = {
bottomSheetState.hideBottomSheet()
viewModel.logOut()
viewModel.logOut(activity)
},
onCancel = {
bottomSheetState.hideBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun MyPageWithdrawalConfirmScreen(
) {
val effectFlow = viewModel.effect

val activity = (LocalContext.current as? Activity)
val activity = LocalContext.current as Activity

LaunchedEffect(true) {
effectFlow.collectLatest { effect ->
Expand All @@ -57,7 +57,7 @@ fun MyPageWithdrawalConfirmScreen(
is MyPageContract.BottomSheet.WithdrawalComplete -> {
bottomSheetState.showBottomSheet {
MyPageWithdrawalCompleteBottomSheet {
activity?.finish()
activity.finish()
}
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ fun MyPageWithdrawalConfirmScreen(

WButton(
text = "계정 삭제",
onClick = { viewModel.withdrawal() },
onClick = { viewModel.withdrawal(activity) },
modifier = Modifier.padding(bottom = 20.dp)
)
}
Expand Down

0 comments on commit ec278ef

Please sign in to comment.