Skip to content

Commit

Permalink
#49 feat/카카오로그인 :
Browse files Browse the repository at this point in the history
1. 코드리뷰 리펙토링 완료
  • Loading branch information
tnvnfdla12 committed Dec 3, 2022
1 parent e8cd963 commit b3275dd
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 28 deletions.
11 changes: 5 additions & 6 deletions app/src/main/java/com/ftw/hometerview/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.ftw.hometerview.R
import com.ftw.hometerview.adapter.AnimationAdapter
import com.ftw.hometerview.databinding.ActivityLoginBinding
import com.ftw.hometerview.ui.main.MainActivity
import com.ftw.hometerview.ui.searchcompany.SearchCompanyActivity
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
Expand Down Expand Up @@ -53,7 +52,7 @@ class LoginActivity : AppCompatActivity() {
setContentView(binding.root)

guideSetting()
ObserveStartActivity()
observeStartActivity()

binding.kakaoLoginButton.setOnClickListener {
kakaoLogin()
Expand All @@ -80,12 +79,12 @@ class LoginActivity : AppCompatActivity() {
binding.dotsIndicator.setViewPager2(binding.guideViewpager)
}

private fun ObserveStartActivity(){
private fun observeStartActivity(){
lifecycleScope.launch {
viewModel.state.collect { state ->
when(state) {
LoginViewModel.State.Success -> {
StartSearchCompanyActivity()
startSearchCompanyActivity()
}
LoginViewModel.State.Failure -> {
toastMessage("로그인에 실패하셨습니다")
Expand All @@ -97,7 +96,7 @@ class LoginActivity : AppCompatActivity() {
}
}
}
private fun StartSearchCompanyActivity(){
private fun startSearchCompanyActivity(){
startActivity(MainActivity.newIntent(this))
finish()
}
Expand All @@ -115,7 +114,7 @@ class LoginActivity : AppCompatActivity() {
// 사용자가 카카오톡 설치 후 디바이스 권한 요청 화면에서 로그인을 취소한 경우,
// 의도적인 로그인 취소로 보고 카카오계정으로 로그인 시도 없이 로그인 취소로 처리 (예: 뒤로 가기)
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
toastMessage("권한이 필요하므로, 다시 한번 시도해주세요!")
toastMessage(getString(R.string.permission_errer_message))
return@loginWithKakaoTalk
}
// 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.ftw.hometerview.ui.login

import android.util.Log
import androidx.lifecycle.ViewModel
import com.ftw.domain.entity.KakaoToken
import com.ftw.domain.usecase.login.LoginUseCase
import com.ftw.hometerview.dispatcher.Dispatcher
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -31,7 +29,6 @@ class LoginViewModel(
_state.value = State.Loading
CoroutineScope(dispatcher.ui()).launch {
val result: Result<Boolean> = loginUseCase.signUp(kakaoToken)
Log.d("adasdas",result.toString())
if(result.isSuccess){
_state.value = State.Success
} else {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="residential_floor_private">비공개</string>
<string name="residential_period">거주 기간</string>
<string name="tip">TIP</string>
<string name="permission_errer_message">권한이 필요하므로, 다시 한번 시도해주세요!</string>

<string name="main_bottom_navigation_menu_home">홈</string>
<string name="main_bottom_navigation_menu_map">지도</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LoginRemoteDataSource(private val api: SignUpAPI) : LoginDataSource {
if (response.isSuccessful) {
val accessToken = response.headers().get("Authorization-Access-Token")
val refreshToken = response.headers().get("Authorization-Refresh-Token")
if(accessToken != null && refreshToken != null){
if (accessToken != null && refreshToken != null) {
return Result.success(JWTToken(accessToken,refreshToken))
}else {
throw ResponseException("Token is Null Exception")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.ftw.data.remote.request

import com.google.gson.annotations.SerializedName

data class KakaoTokenReq (
@SerializedName("accessToken") val accessToken : String,
@SerializedName("refreshToken") val refreshToken : String
)
data class KakaoTokenReq(
@SerializedName("accessToken") val accessToken: String,
@SerializedName("refreshToken") val refreshToken: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import com.ftw.domain.repository.login.LoginRepository

class LoginRepositoryImpl(private val loginDataSource: LoginDataSource) : LoginRepository {

override suspend fun setKaKaoToken(kakaoToken: KakaoToken): Result<JWTToken> {
val result = loginDataSource.setKakaoToken(kakaoToken)
result.getOrNull()?.let {
return Result.success(it)
}
return Result.failure(IllegalAccessException("LoginRepositoryImpl에러"))
override suspend fun setKaKaoToken(kakaoToken: KakaoToken): Result<JWTToken> { //근데 실패하면 뭐가 나오는지 궁금함
return loginDataSource.setKakaoToken(kakaoToken).let { it }
}
}
2 changes: 1 addition & 1 deletion domain/src/main/java/com/ftw/domain/entity/JWTToken.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.ftw.domain.entity
data class JWTToken (
val accessToken : String,
val refreshToken : String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ class LoginUseCaseImpl(

//1. 서버에 카카오 토큰을 넘겨 서버에 저장
//2. 받아올 jwt토큰을 로컬에 저장
override suspend fun signUp(kakaoToken: KakaoToken):Result<Boolean>{
val serverResult = loginRepository.setKaKaoToken(kakaoToken)
serverResult.getOrNull()?.let {
tokenRepository.setUserToken(it)
return Result.success(true)
}
return Result.failure(IllegalAccessException("signUp 실패"))
override suspend fun signUp(kakaoToken: KakaoToken): Result<Boolean> {
val token = loginRepository.setKaKaoToken(kakaoToken).getOrNull() ?: return Result.failure(
IllegalAccessException("signUp 실패")
)
tokenRepository.setUserToken(token)
return Result.success(true)
}
}

0 comments on commit b3275dd

Please sign in to comment.