Skip to content

Commit

Permalink
#42 / access Token 얻는 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
taeheeL committed Jul 18, 2023
1 parent a65040a commit 21b2c2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AuthRepositoryImpl @Inject constructor(
kotlin.runCatching {
authDatasource.getToken(social, RequestAuthDto(code)).toToken()
}.onSuccess {
Result.success(it.toToken())
Result.success(it)
}.onFailure {
Result.failure<Token>(it)
}
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/sopt/uni/presentation/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
Timber.e("Kakao Login Success ${it.token} ${it.id}")
}

is KakaoLoginService.LoginState.Failure -> Timber.d("Kakao Login Failed ${it.error}")
else -> Timber.d("Kakao INIT")
is KakaoLoginService.LoginState.Failure -> {
Timber.d("Kakao Login Failed ${it.error}")
}

else -> {
Timber.d("Kakao INIT")
}
}
}
}
Expand All @@ -88,7 +93,6 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
.requestEmail()
.requestId()
.requestProfile()
.requestServerAuthCode("$GOOGLE_CLIENT_ID")
.build()

mGoogleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions)
Expand All @@ -102,8 +106,8 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo

try {
val account = task.getResult(ApiException::class.java)!!
Timber.e("firebaseAuthWithGoogle:" + account.serverAuthCode)
loginViewModel.getAccessToken("google", account.serverAuthCode.toString())
Timber.e("firebaseAuthWithGoogle:" + account.idToken)
loginViewModel.getAccessToken("google", account.idToken!!)
firebaseAuthWithGoogle(account.idToken!!)
} catch (e: ApiException) {
Timber.e("Google sign in failed", e)
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/java/sopt/uni/presentation/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ class LoginViewModel @Inject constructor(

fun getAccessToken(social: String, code: String) {
viewModelScope.launch {
kotlin.runCatching {
authRepository.getToken(social, code)
}.onSuccess {
SparkleStorage.accessToken = it.getOrNull()?.accessToken ?: ""
_loginResult.value = InHouseLoginState.Success
Timber.e("getAccessToken: ${SparkleStorage.accessToken}")
}.onFailure {
_loginResult.value = InHouseLoginState.Failure(it.message ?: "로그인에 실패했습니다.")
}
authRepository.getToken(social, code)
.onSuccess { token ->
SparkleStorage.accessToken = token.accessToken
_loginResult.value = InHouseLoginState.Success
Timber.tag("accessToken").d("getAccessToken with server: $token.accessToken")
}.onFailure {
_loginResult.value = InHouseLoginState.Failure(it.message ?: "로그인에 실패했습니다.")
}
}
}

Expand Down

0 comments on commit 21b2c2c

Please sign in to comment.