Skip to content

Commit

Permalink
[FEAT]#7: Lint 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 15, 2024
1 parent 50bad3b commit 7df6549
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/bff/wespot/WeSpotApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class WeSpotApplication : Application() {
val key = BuildConfig.KAKAO_APP_KEY
KakaoSdk.init(this, key)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
95 changes: 48 additions & 47 deletions feature/auth/src/main/kotlin/com/bff/wespot/auth/KakaoLogin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<OAuthToken>.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<OAuthToken>.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
}
KAKAO_TALK_LOGIN,
KAKAO_ACCOUNT_LOGIN,
}

0 comments on commit 7df6549

Please sign in to comment.