diff --git a/app/src/main/kotlin/com/bff/wespot/WeSpotApplication.kt b/app/src/main/kotlin/com/bff/wespot/WeSpotApplication.kt index f6ebf471..1c5ee3a5 100644 --- a/app/src/main/kotlin/com/bff/wespot/WeSpotApplication.kt +++ b/app/src/main/kotlin/com/bff/wespot/WeSpotApplication.kt @@ -10,4 +10,4 @@ class WeSpotApplication : Application() { val key = BuildConfig.KAKAO_APP_KEY KakaoSdk.init(this, key) } -} \ No newline at end of file +} diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthScreen.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthScreen.kt index c610ba59..5ab750b5 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthScreen.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthScreen.kt @@ -20,10 +20,9 @@ fun AuthScreen() { val coroutineScope = rememberCoroutineScope() val kakaoLoginManager = KakaoLoginManager(context) - Box( modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { Button(onClick = { coroutineScope.launch { diff --git a/feature/auth/src/main/kotlin/com/bff/wespot/auth/KakaoLogin.kt b/feature/auth/src/main/kotlin/com/bff/wespot/auth/KakaoLogin.kt index 9f76a2ba..a75a9d45 100644 --- a/feature/auth/src/main/kotlin/com/bff/wespot/auth/KakaoLogin.kt +++ b/feature/auth/src/main/kotlin/com/bff/wespot/auth/KakaoLogin.kt @@ -12,70 +12,71 @@ import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine -class KakaoLoginManager @Inject constructor( - @ActivityContext private val context: Context -) { +class KakaoLoginManager + @Inject + constructor( + @ActivityContext private val context: Context, + ) { + suspend fun loginWithKakao(): OAuthToken { + val loginState = getKakaoLoginState() - suspend fun loginWithKakao(): OAuthToken { - val loginState = getKakaoLoginState() + return when (loginState) { + KaKaoLoginState.KAKAO_TALK_LOGIN -> { + try { + UserApiClient.loginWithKakaoTalk() + } catch (error: Throwable) { + if (error is ClientError && error.reason == ClientErrorCause.Cancelled) { + throw error + } - return when (loginState) { - KaKaoLoginState.KAKAO_TALK_LOGIN -> { - try { - UserApiClient.loginWithKakaoTalk() - } catch (error: Throwable) { - if (error is ClientError && error.reason == ClientErrorCause.Cancelled) { - throw error + UserApiClient.loginWithKakaoAccount() } + } + KaKaoLoginState.KAKAO_ACCOUNT_LOGIN -> { UserApiClient.loginWithKakaoAccount() } } - - KaKaoLoginState.KAKAO_ACCOUNT_LOGIN -> { - UserApiClient.loginWithKakaoAccount() - } } - } - - private suspend fun UserApiClient.Companion.loginWithKakaoTalk(): OAuthToken { - return suspendCoroutine { continuation -> - instance.loginWithKakaoTalk(context) { token, error -> - continuation.resumeTokenOrException(token, error) + private suspend fun UserApiClient.Companion.loginWithKakaoTalk(): OAuthToken { + return suspendCoroutine { continuation -> + instance.loginWithKakaoTalk(context) { token, error -> + continuation.resumeTokenOrException(token, error) + } } } - } - private suspend fun UserApiClient.Companion.loginWithKakaoAccount(): OAuthToken { - return suspendCoroutine { continuation -> - instance.loginWithKakaoAccount(context) { token, error -> - continuation.resumeTokenOrException(token, error) + private suspend fun UserApiClient.Companion.loginWithKakaoAccount(): OAuthToken { + return suspendCoroutine { continuation -> + instance.loginWithKakaoAccount(context) { token, error -> + continuation.resumeTokenOrException(token, error) + } } } - } - private fun getKakaoLoginState(): KaKaoLoginState = - if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) { - KaKaoLoginState.KAKAO_TALK_LOGIN - } else { - KaKaoLoginState.KAKAO_ACCOUNT_LOGIN - } + private fun getKakaoLoginState(): KaKaoLoginState = + if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) { + KaKaoLoginState.KAKAO_TALK_LOGIN + } else { + KaKaoLoginState.KAKAO_ACCOUNT_LOGIN + } - private fun Continuation.resumeTokenOrException( - token: OAuthToken?, - error: Throwable? - ) { - if (error != null) { - resumeWithException(error) - } else if (token != null) { - resume(token) - } else { - resumeWithException(RuntimeException("Failed to get kakao access token, reason is not clear.")) + private fun Continuation.resumeTokenOrException( + token: OAuthToken?, + error: Throwable?, + ) { + if (error != null) { + resumeWithException(error) + } else if (token != null) { + resume(token) + } else { + resumeWithException(RuntimeException("Failed to get kakao access token, reason is not clear.")) + } } } -} enum class KaKaoLoginState { - KAKAO_TALK_LOGIN, KAKAO_ACCOUNT_LOGIN -} \ No newline at end of file + KAKAO_TALK_LOGIN, + KAKAO_ACCOUNT_LOGIN, +}