diff --git a/app/src/main/java/com/ftw/hometerview/ui/login/LoginActivity.kt b/app/src/main/java/com/ftw/hometerview/ui/login/LoginActivity.kt index 540fc7e..3a5154d 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/login/LoginActivity.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/login/LoginActivity.kt @@ -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 @@ -53,7 +52,7 @@ class LoginActivity : AppCompatActivity() { setContentView(binding.root) guideSetting() - ObserveStartActivity() + observeStartActivity() binding.kakaoLoginButton.setOnClickListener { kakaoLogin() @@ -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("로그인에 실패하셨습니다") @@ -97,7 +96,7 @@ class LoginActivity : AppCompatActivity() { } } } - private fun StartSearchCompanyActivity(){ + private fun startSearchCompanyActivity(){ startActivity(MainActivity.newIntent(this)) finish() } @@ -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 } // 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도 diff --git a/app/src/main/java/com/ftw/hometerview/ui/login/LoginViewModel.kt b/app/src/main/java/com/ftw/hometerview/ui/login/LoginViewModel.kt index a6bea9b..6aa9138 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/login/LoginViewModel.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/login/LoginViewModel.kt @@ -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 @@ -31,7 +29,6 @@ class LoginViewModel( _state.value = State.Loading CoroutineScope(dispatcher.ui()).launch { val result: Result = loginUseCase.signUp(kakaoToken) - Log.d("adasdas",result.toString()) if(result.isSuccess){ _state.value = State.Success } else { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 63f451d..9403cb2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,6 +16,7 @@ 비공개 거주 기간 TIP + 권한이 필요하므로, 다시 한번 시도해주세요! 지도 diff --git a/data/src/main/java/com/ftw/data/remote/datasource/LoginRemoteDataSource.kt b/data/src/main/java/com/ftw/data/remote/datasource/LoginRemoteDataSource.kt index c2cce78..d46d8ba 100644 --- a/data/src/main/java/com/ftw/data/remote/datasource/LoginRemoteDataSource.kt +++ b/data/src/main/java/com/ftw/data/remote/datasource/LoginRemoteDataSource.kt @@ -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") diff --git a/data/src/main/java/com/ftw/data/remote/request/KakaoTokenReq.kt b/data/src/main/java/com/ftw/data/remote/request/KakaoTokenReq.kt index 3b070db..2c0319b 100644 --- a/data/src/main/java/com/ftw/data/remote/request/KakaoTokenReq.kt +++ b/data/src/main/java/com/ftw/data/remote/request/KakaoTokenReq.kt @@ -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 - ) \ No newline at end of file +data class KakaoTokenReq( + @SerializedName("accessToken") val accessToken: String, + @SerializedName("refreshToken") val refreshToken: String +) \ No newline at end of file diff --git a/data/src/main/java/com/ftw/data/repository/login/LoginRepositoryImpl.kt b/data/src/main/java/com/ftw/data/repository/login/LoginRepositoryImpl.kt index 2f33395..cf382d5 100644 --- a/data/src/main/java/com/ftw/data/repository/login/LoginRepositoryImpl.kt +++ b/data/src/main/java/com/ftw/data/repository/login/LoginRepositoryImpl.kt @@ -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 { - val result = loginDataSource.setKakaoToken(kakaoToken) - result.getOrNull()?.let { - return Result.success(it) - } - return Result.failure(IllegalAccessException("LoginRepositoryImpl에러")) + override suspend fun setKaKaoToken(kakaoToken: KakaoToken): Result { //근데 실패하면 뭐가 나오는지 궁금함 + return loginDataSource.setKakaoToken(kakaoToken).let { it } } } diff --git a/domain/src/main/java/com/ftw/domain/entity/JWTToken.kt b/domain/src/main/java/com/ftw/domain/entity/JWTToken.kt index d60f830..ae8e33c 100644 --- a/domain/src/main/java/com/ftw/domain/entity/JWTToken.kt +++ b/domain/src/main/java/com/ftw/domain/entity/JWTToken.kt @@ -3,4 +3,4 @@ package com.ftw.domain.entity data class JWTToken ( val accessToken : String, val refreshToken : String - ) \ No newline at end of file +) \ No newline at end of file diff --git a/domain/src/main/java/com/ftw/domain/usecase/login/LoginUseCaseImpl.kt b/domain/src/main/java/com/ftw/domain/usecase/login/LoginUseCaseImpl.kt index f5e6184..f712dae 100644 --- a/domain/src/main/java/com/ftw/domain/usecase/login/LoginUseCaseImpl.kt +++ b/domain/src/main/java/com/ftw/domain/usecase/login/LoginUseCaseImpl.kt @@ -11,12 +11,11 @@ class LoginUseCaseImpl( //1. 서버에 카카오 토큰을 넘겨 서버에 저장 //2. 받아올 jwt토큰을 로컬에 저장 - override suspend fun signUp(kakaoToken: KakaoToken):Result{ - 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 { + val token = loginRepository.setKaKaoToken(kakaoToken).getOrNull() ?: return Result.failure( + IllegalAccessException("signUp 실패") + ) + tokenRepository.setUserToken(token) + return Result.success(true) } }