From 86755004b5b88870af2202d8909cdce50fee0436 Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:38:03 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#6=20feat=20:=20App=EC=97=90=EC=84=9C=20nav?= =?UTF-8?q?erLoginSDK=20=EC=B4=88=EA=B8=B0=ED=99=94,=20intent=20flag=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/avengers/nibobnebob/app/App.kt | 17 +++++++++++++++++ .../ui/intro/login/LoginFragment.kt | 11 +---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt index e0923c0..90a8d3d 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt @@ -5,12 +5,29 @@ import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.preferencesDataStore +import com.avengers.nibobnebob.BuildConfig import com.avengers.nibobnebob.presentation.util.Constants.APP_NAME +import com.navercorp.nid.NaverIdLoginSDK import dagger.hilt.android.HiltAndroidApp @HiltAndroidApp class App : Application(){ + + override fun onCreate() { + super.onCreate() + initializeNaverSDK() + } + companion object{ val Context.dataStore: DataStore by preferencesDataStore(name = APP_NAME) } + + private fun initializeNaverSDK(){ + NaverIdLoginSDK.initialize( + applicationContext, + BuildConfig.NAVER_LOGIN_CLIENT_ID, + BuildConfig.NAVER_LOGIN_CLIENT_SECRET, + "Naver") + NaverIdLoginSDK.showDevelopersLog(true) + } } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt index 5cf555e..ee9bf76 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt @@ -31,7 +31,6 @@ class LoginFragment : BaseFragment(R.layout.fragment_login override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.vm = viewModel - naverInitialize() initEventObserver() binding.btnNaver.setOnClickListener { @@ -53,14 +52,6 @@ class LoginFragment : BaseFragment(R.layout.fragment_login } } - private fun naverInitialize(){ - NaverIdLoginSDK.initialize( - requireContext(), - BuildConfig.NAVER_LOGIN_CLIENT_ID, - BuildConfig.NAVER_LOGIN_CLIENT_SECRET, TAG) - NaverIdLoginSDK.showDevelopersLog(true) - } - private fun naverLogin(){ val oAuthLoginCallback = object : OAuthLoginCallback{ override fun onError(errorCode: Int, message: String) { @@ -88,7 +79,7 @@ class LoginFragment : BaseFragment(R.layout.fragment_login private fun NavController.toMainActivity(){ val intent = Intent(context, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) - (activity as IntroActivity).finish() } } \ No newline at end of file From 74b9c99b4afe47bf68249360197d5f659757e65c Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:03:50 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#6=20feat=20:=20login=20to=20signUp?= =?UTF-8?q?=EC=97=90=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 네이버 로그인시 사용자 프로필에 대한 이메일을 받아온 후 signupDetail에 전달 --- .../java/com/avengers/nibobnebob/app/App.kt | 2 +- .../presentation/ui/intro/login/Info.kt | 6 ------ .../ui/intro/login/LoginFragment.kt | 21 ++++++++++++++++++- .../ui/intro/login/LoginViewModel.kt | 8 ++++--- .../ui/intro/login/model/UiLoginData.kt | 6 ++++++ 5 files changed, 32 insertions(+), 11 deletions(-) delete mode 100644 Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/Info.kt create mode 100644 Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/model/UiLoginData.kt diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt index 90a8d3d..9740861 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt @@ -27,7 +27,7 @@ class App : Application(){ applicationContext, BuildConfig.NAVER_LOGIN_CLIENT_ID, BuildConfig.NAVER_LOGIN_CLIENT_SECRET, - "Naver") + APP_NAME) NaverIdLoginSDK.showDevelopersLog(true) } } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/Info.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/Info.kt deleted file mode 100644 index 65758e3..0000000 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/Info.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.avengers.nibobnebob.presentation.ui.intro.login - -data class CommonRequest( - val email : String ="", - val password : String ="" -) \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt index ee9bf76..4614a55 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt @@ -16,7 +16,10 @@ import com.avengers.nibobnebob.presentation.ui.intro.IntroActivity import com.avengers.nibobnebob.presentation.ui.intro.IntroViewModel import com.avengers.nibobnebob.presentation.ui.main.MainActivity import com.navercorp.nid.NaverIdLoginSDK +import com.navercorp.nid.oauth.NidOAuthLogin import com.navercorp.nid.oauth.OAuthLoginCallback +import com.navercorp.nid.profile.NidProfileCallback +import com.navercorp.nid.profile.data.NidProfileResponse import dagger.hilt.android.AndroidEntryPoint @@ -66,6 +69,20 @@ class LoginFragment : BaseFragment(R.layout.fragment_login override fun onSuccess() { val token = NaverIdLoginSDK.getAccessToken().toString() + NidOAuthLogin().callProfileApi(object : NidProfileCallback{ + override fun onError(errorCode: Int, message: String) { + onFailure(errorCode, message) + } + override fun onFailure(httpStatus: Int, message: String) { + val errorCode = NaverIdLoginSDK.getLastErrorCode().code + val errorDescription = NaverIdLoginSDK.getLastErrorDescription() + Log.d(TAG,"errorCode:$errorCode, errorDesc:$errorDescription") + } + + override fun onSuccess(result: NidProfileResponse) { + viewModel.naverEmail.value = result.profile?.email.toString() + } + }) viewModel.loginNaver(token) } } @@ -73,7 +90,9 @@ class LoginFragment : BaseFragment(R.layout.fragment_login } private fun NavController.toDetailSignup(){ - val action = LoginFragmentDirections.actionLoginFragmentToDetailSignupFragment() + val action = LoginFragmentDirections.actionLoginFragmentToDetailSignupFragment( + email = viewModel.naverEmail.value + ) this.navigate(action) } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt index 1796a42..6d06cd8 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope import com.avengers.nibobnebob.app.DataStoreManager import com.avengers.nibobnebob.data.model.ApiState import com.avengers.nibobnebob.data.repository.IntroRepository +import com.avengers.nibobnebob.presentation.ui.intro.login.model.UiLoginData import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -33,12 +34,13 @@ class LoginViewModel @Inject constructor( private val _events = MutableSharedFlow() val events = _events.asSharedFlow() - private val _uiState = MutableStateFlow(CommonRequest()) + private val _uiState = MutableStateFlow(UiLoginData()) val uiState = _uiState.asStateFlow() val email = MutableStateFlow("") val password = MutableStateFlow("") val autoLogin = MutableStateFlow(false) + val naverEmail = MutableStateFlow("") init { observeEmail() @@ -84,7 +86,7 @@ class LoginViewModel @Inject constructor( is ApiState.Error -> { when(it.statusCode){ 401 -> { - Log.d(TAG,"401이 뜰일이 있나..?") + Log.d(TAG,"401 에러") } 404 -> { _events.emit(LoginEvent.NavigateToDetailSignup) @@ -92,7 +94,7 @@ class LoginViewModel @Inject constructor( } } is ApiState.Exception -> { - Log.d(TAG,"예외처리?") + Log.d(TAG,"예외처리") } } }.launchIn(viewModelScope) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/model/UiLoginData.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/model/UiLoginData.kt new file mode 100644 index 0000000..c57843a --- /dev/null +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/model/UiLoginData.kt @@ -0,0 +1,6 @@ +package com.avengers.nibobnebob.presentation.ui.intro.login.model + +data class UiLoginData( + val email : String ="", + val password : String ="" +) \ No newline at end of file From c5d25f4e0e00b72339d8e35ff00b9bf82aa794f2 Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:05:29 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#3=20refactor=20:=20splashviewmodel=20uiEve?= =?UTF-8?q?nt=20=EB=B3=B4=EC=9D=BC=EB=9F=AC=ED=94=8C=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EA=B0=90=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 뷰모델 내부 상에 있는 uiEvent을 분리 시킴 --- .../presentation/ui/splash/SplashActivity.kt | 8 +++---- .../presentation/ui/splash/SplashViewModel.kt | 21 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashActivity.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashActivity.kt index 2f627d3..70e24c9 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashActivity.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashActivity.kt @@ -29,20 +29,20 @@ class SplashActivity : BaseActivity(ActivitySplashBinding repeatOnStarted { viewModel.events.collect { when (it) { - is SplashViewModel.NavigationEvent.NavigateToIntro -> moveToIntroActivity() - is SplashViewModel.NavigationEvent.NavigateToMain -> moveToMainActivity() + is SplashUiEvent.NavigateToIntro -> toIntroActivity() + is SplashUiEvent.NavigateToMain -> toMainActivity() } } } } - private fun moveToMainActivity() { + private fun toMainActivity() { val intent = Intent(this, MainActivity::class.java) startActivity(intent) finish() } - private fun moveToIntroActivity() { + private fun toIntroActivity() { val intent = Intent(this, IntroActivity::class.java) startActivity(intent) finish() diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashViewModel.kt index 341c017..11ddf45 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/splash/SplashViewModel.kt @@ -7,32 +7,31 @@ import com.avengers.nibobnebob.presentation.base.BaseActivityViewModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.launch import javax.inject.Inject +sealed class SplashUiEvent { + data object NavigateToMain : SplashUiEvent() + data object NavigateToIntro : SplashUiEvent() +} + @HiltViewModel class SplashViewModel @Inject constructor( private val networkManager: NetworkManager, private val dataStoreManager: DataStoreManager, ) : BaseActivityViewModel(networkManager) { - - sealed class NavigationEvent { - data object NavigateToMain : NavigationEvent() - data object NavigateToIntro : NavigationEvent() - } - - private val TAG = "SplashViewModelDebug" - private val _events = MutableSharedFlow() - val events: SharedFlow get() = _events + private val _events = MutableSharedFlow() + val events: SharedFlow = _events.asSharedFlow() fun getAutoLogin() { viewModelScope.launch { dataStoreManager.getAutoLogin().collect { autoLogin -> dataStoreManager.getAccessToken().collect { accessToken -> if (autoLogin == true && accessToken != "") { - _events.emit(NavigationEvent.NavigateToMain) + _events.emit(SplashUiEvent.NavigateToMain) } else { - _events.emit(NavigationEvent.NavigateToIntro) + _events.emit(SplashUiEvent.NavigateToIntro) } } } From f46e1ab488ed0331f670193eb9db56e12a2f5c70 Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:19:16 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#6=20feat=20:=20interceptor=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B2=84=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=EA=B3=BC=20?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EB=B6=84=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 네이버 로그인 시 retrofit을 통해 header삽입 및 interceptor 형식 정의 --- .../nibobnebob/config/AccessTokenInterceptor.kt | 13 +++++++------ .../com/avengers/nibobnebob/data/remote/IntroApi.kt | 5 ++++- .../nibobnebob/data/repository/IntroRepository.kt | 2 +- .../data/repository/IntroRepositoryImpl.kt | 5 +++-- .../presentation/ui/intro/login/LoginViewModel.kt | 4 +--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt index 3242eb1..7976b18 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/config/AccessTokenInterceptor.kt @@ -2,8 +2,8 @@ package com.avengers.nibobnebob.config import android.util.Log import com.avengers.nibobnebob.app.DataStoreManager -import com.avengers.nibobnebob.presentation.util.Constants.ACCESS import com.avengers.nibobnebob.presentation.util.Constants.AUTHORIZATION +import com.avengers.nibobnebob.presentation.util.Constants.BEARER import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import okhttp3.Interceptor @@ -12,19 +12,20 @@ import okhttp3.Response import java.io.IOException import javax.inject.Inject -class AccessTokenInterceptor @Inject constructor(private val dataStoreManager: DataStoreManager): Interceptor { +class AccessTokenInterceptor @Inject constructor(private val dataStoreManager: DataStoreManager) : + Interceptor { @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { // 동기가 아닌 비동기로 불러와야한다.. runBlocking말고 다른 방안에 대해 고민 - val accessToken = runBlocking { + val accessToken = runBlocking { dataStoreManager.getAccessToken().first() } - Log.d("토큰 테스트",accessToken.toString()) + Log.d("토큰 테스트", accessToken.toString()) val builder: Request.Builder = chain.request().newBuilder() - accessToken.let { - builder.addHeader(AUTHORIZATION,"$ACCESS $accessToken") + accessToken?.takeIf { it.isNotEmpty() }?.let { + builder.addHeader(AUTHORIZATION, "$BEARER $it") } return chain.proceed(builder.build()) } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt index 6086bc3..0cb5298 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt @@ -4,6 +4,7 @@ import com.avengers.nibobnebob.data.model.request.DetailSignupRequest import com.avengers.nibobnebob.data.model.response.NaverLoginResponse import retrofit2.Response import retrofit2.http.Body +import retrofit2.http.Header import retrofit2.http.POST interface IntroApi { @@ -14,5 +15,7 @@ interface IntroApi { ): Response @POST("api/auth/social-login") - suspend fun loginNaver(): Response + suspend fun loginNaver( + @Header("Authorization")token : String + ): Response } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt index 2692be8..54f1e55 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt @@ -11,5 +11,5 @@ interface IntroRepository { body: DetailSignupRequest ): Flow> - fun loginNaver(): Flow> + fun loginNaver(token : String): Flow> } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt index 6e3ae20..8b4a32b 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt @@ -5,6 +5,7 @@ import com.avengers.nibobnebob.data.model.request.DetailSignupRequest import com.avengers.nibobnebob.data.model.response.NaverLoginResponse import com.avengers.nibobnebob.data.model.runNNApi import com.avengers.nibobnebob.data.remote.IntroApi +import com.avengers.nibobnebob.presentation.util.Constants.ACCESS import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject @@ -18,8 +19,8 @@ class IntroRepositoryImpl @Inject constructor( emit(result) } - override fun loginNaver(): Flow> = flow { - val result = runNNApi { api.loginNaver() } + override fun loginNaver(token : String): Flow> = flow { + val result = runNNApi { api.loginNaver("$ACCESS $token") } emit(result) } } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt index 6d06cd8..40f31be 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt @@ -73,14 +73,12 @@ class LoginViewModel @Inject constructor( fun loginNaver(token : String){ viewModelScope.launch { - dataStoreManager.putAccessToken(token) - introRepository.loginNaver().onEach { + introRepository.loginNaver(token).onEach { when(it){ is ApiState.Success -> { dataStoreManager.putAutoLogin(true) dataStoreManager.putAccessToken(it.data.accessToken.toString()) dataStoreManager.putRefreshToken(it.data.refreshToken.toString()) - _events.emit(LoginEvent.NavigateToMain) } is ApiState.Error -> { From 50e5869891b0c4b7e71ee02b936146cea137f572 Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:25:46 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#6=20refactor=20:=20Intro=20data=20layer=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B2=98=EB=A6=AC=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nibobnebob/data/remote/IntroApi.kt | 3 ++- .../data/repository/IntroRepository.kt | 5 ++-- .../data/repository/IntroRepositoryImpl.kt | 4 ++-- .../ui/intro/login/LoginViewModel.kt | 23 ++++++++----------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt index 0cb5298..47643db 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/remote/IntroApi.kt @@ -1,6 +1,7 @@ package com.avengers.nibobnebob.data.remote import com.avengers.nibobnebob.data.model.request.DetailSignupRequest +import com.avengers.nibobnebob.data.model.response.BaseResponse import com.avengers.nibobnebob.data.model.response.NaverLoginResponse import retrofit2.Response import retrofit2.http.Body @@ -17,5 +18,5 @@ interface IntroApi { @POST("api/auth/social-login") suspend fun loginNaver( @Header("Authorization")token : String - ): Response + ): Response> } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt index ae582d8..24bee85 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepository.kt @@ -12,6 +12,7 @@ interface IntroRepository { body: DetailSignupRequest ): Flow> - fun loginNaver(token : String): Flow> - fun loginNaver(): Flow>> + fun loginNaver( + token: String + ): Flow>> } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt index 5f2aded..8189e99 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/repository/IntroRepositoryImpl.kt @@ -20,8 +20,8 @@ class IntroRepositoryImpl @Inject constructor( emit(result) } - override fun loginNaver(token : String): Flow> = flow { - val result = runNNApi { api.loginNaver("$ACCESS $token") } + override fun loginNaver(token : String): Flow>> = flow { + val result = runRemote { api.loginNaver("$ACCESS $token") } emit(result) } } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt index fbe6448..b96cf9d 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.avengers.nibobnebob.app.DataStoreManager import com.avengers.nibobnebob.data.model.BaseState +import com.avengers.nibobnebob.data.model.StatusCode import com.avengers.nibobnebob.data.repository.IntroRepository import com.avengers.nibobnebob.presentation.ui.intro.login.model.UiLoginData import dagger.hilt.android.lifecycle.HiltViewModel @@ -73,27 +74,23 @@ class LoginViewModel @Inject constructor( fun loginNaver(token : String){ viewModelScope.launch { - introRepository.loginNaver(token).onEach { - when(it){ + introRepository.loginNaver(token).onEach { state -> + when(state){ is BaseState.Success -> { dataStoreManager.putAutoLogin(true) - dataStoreManager.putAccessToken(it.data.accessToken.toString()) - dataStoreManager.putRefreshToken(it.data.refreshToken.toString()) + dataStoreManager.putAccessToken(state.data.body.accessToken.toString()) + dataStoreManager.putRefreshToken(state.data.body.refreshToken.toString()) _events.emit(LoginEvent.NavigateToMain) } is BaseState.Error -> { - when(it.statusCode){ - 401 -> { - Log.d(TAG,"401 에러") - } - 404 -> { - _events.emit(LoginEvent.NavigateToDetailSignup) + when(state.statusCode){ + StatusCode.ERROR_AUTH-> {Log.d(TAG,"토큰 오류")} + StatusCode.ERROR_NONE ->{ _events.emit(LoginEvent.NavigateToDetailSignup)} + else ->{ + Log.d(TAG,"오류 Exception") } } } - is ApiState.Exception -> { - Log.d(TAG,"예외처리") - } } }.launchIn(viewModelScope) } From cd95ac0e56aaddcf3319a6587b493fefa8db44bb Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:26:00 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#6=20feat=20:=20BaseState=20=EB=B6=84?= =?UTF-8?q?=EA=B8=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aos/.idea/deploymentTargetDropDown.xml | 17 ----------------- .../avengers/nibobnebob/data/model/BaseState.kt | 10 ++++++++-- 2 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 Aos/.idea/deploymentTargetDropDown.xml diff --git a/Aos/.idea/deploymentTargetDropDown.xml b/Aos/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index a682024..0000000 --- a/Aos/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/data/model/BaseState.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/data/model/BaseState.kt index c8f30f9..eb6531f 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/data/model/BaseState.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/data/model/BaseState.kt @@ -6,7 +6,9 @@ import retrofit2.Response enum class StatusCode{ EMPTY, ERROR, - EXCEPTION + EXCEPTION, + ERROR_AUTH, + ERROR_NONE } sealed class BaseState { @@ -23,7 +25,11 @@ suspend fun runRemote(block: suspend () -> Response): BaseState { } ?: BaseState.Error(StatusCode.EMPTY, "응답이 비어있습니다") } else { val errorData = Gson().fromJson(response.errorBody()?.string(), BaseState.Error::class.java) - BaseState.Error(StatusCode.ERROR, errorData.message) + when(response.code()){ + 401 -> BaseState.Error(StatusCode.ERROR_AUTH, errorData.message) + 404 -> BaseState.Error(StatusCode.ERROR_NONE, errorData.message) + else -> BaseState.Error(StatusCode.ERROR, errorData.message) + } } } catch (e: Exception) { BaseState.Error(StatusCode.EXCEPTION, e.message.toString()) From fa1acc457673ec51a2497553c57032e212e94cf8 Mon Sep 17 00:00:00 2001 From: BENDENG1 <76191161+BENDENG1@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:02:04 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#6=20feat=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EB=B9=84=EB=8F=99=EA=B8=B0=20=EC=B2=98=EB=A6=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 네이버 콜백이 비동기이므로 모든 콜백 후 서버와의 통신 진행 --- .../nibobnebob/presentation/ui/intro/login/LoginFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt index 4614a55..ada8e9e 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/intro/login/LoginFragment.kt @@ -81,9 +81,9 @@ class LoginFragment : BaseFragment(R.layout.fragment_login override fun onSuccess(result: NidProfileResponse) { viewModel.naverEmail.value = result.profile?.email.toString() + viewModel.loginNaver(token) } }) - viewModel.loginNaver(token) } } NaverIdLoginSDK.authenticate(requireContext(), oAuthLoginCallback)