diff --git a/core/data/src/main/java/com/goalpanzi/mission_mate/core/data/repository/LoginRepositoryImpl.kt b/core/data/src/main/java/com/goalpanzi/mission_mate/core/data/repository/LoginRepositoryImpl.kt index f7ebc6aa..d7e143b9 100644 --- a/core/data/src/main/java/com/goalpanzi/mission_mate/core/data/repository/LoginRepositoryImpl.kt +++ b/core/data/src/main/java/com/goalpanzi/mission_mate/core/data/repository/LoginRepositoryImpl.kt @@ -3,6 +3,7 @@ package com.goalpanzi.mission_mate.core.data.repository import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository import com.goalpanzi.mission_mate.core.network.service.LoginService import com.luckyoct.core.model.GoogleLogin +import com.luckyoct.core.model.base.NetworkResult import com.luckyoct.core.model.request.GoogleLoginRequest import javax.inject.Inject @@ -10,9 +11,8 @@ class LoginRepositoryImpl @Inject constructor( private val loginService: LoginService ): LoginRepository { - override suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin { - val request = GoogleLoginRequest(identityToken = token, email = email) - val response = loginService.requestGoogleLogin(request) - return response + override suspend fun requestGoogleLogin(email: String) = handleResult { + val request = GoogleLoginRequest(email = email) + loginService.requestGoogleLogin(request) } } \ No newline at end of file diff --git a/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/repository/LoginRepository.kt b/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/repository/LoginRepository.kt index 8796fb70..a75841da 100644 --- a/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/repository/LoginRepository.kt +++ b/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/repository/LoginRepository.kt @@ -1,7 +1,9 @@ package com.goalpanzi.mission_mate.core.domain.repository +import com.goalpanzi.mission_mate.core.network.ResultHandler import com.luckyoct.core.model.GoogleLogin +import com.luckyoct.core.model.base.NetworkResult -interface LoginRepository { - suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin +interface LoginRepository : ResultHandler { + suspend fun requestGoogleLogin(email: String): NetworkResult } \ No newline at end of file diff --git a/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/LoginUseCase.kt b/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/LoginUseCase.kt index 250dfc21..b780102f 100644 --- a/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/LoginUseCase.kt +++ b/core/domain/src/main/java/com/goalpanzi/mission_mate/core/domain/usecase/LoginUseCase.kt @@ -3,19 +3,26 @@ package com.goalpanzi.mission_mate.core.domain.usecase import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository import com.luckyoct.core.model.GoogleLogin +import com.luckyoct.core.model.base.NetworkResult +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flow import javax.inject.Inject class LoginUseCase @Inject constructor( private val loginRepository: LoginRepository, private val authDataSource: AuthDataSource ) { - - suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin { - val response = loginRepository.requestGoogleLogin(token, email) - authDataSource.setAccessToken(response.accessToken).first() - authDataSource.setRefreshToken(response.refreshToken).first() - return response + suspend fun requestGoogleLogin(email: String): GoogleLogin? { + return when (val response = loginRepository.requestGoogleLogin(email)) { + is NetworkResult.Success -> { + response.data.also { + authDataSource.setAccessToken(it.accessToken).first() + authDataSource.setRefreshToken(it.refreshToken).first() + } + } + is NetworkResult.Error, is NetworkResult.Exception -> null + } } } \ No newline at end of file diff --git a/core/model/src/main/java/com/luckyoct/core/model/request/GoogleLoginRequest.kt b/core/model/src/main/java/com/luckyoct/core/model/request/GoogleLoginRequest.kt index 58cd0f23..642b6cfc 100644 --- a/core/model/src/main/java/com/luckyoct/core/model/request/GoogleLoginRequest.kt +++ b/core/model/src/main/java/com/luckyoct/core/model/request/GoogleLoginRequest.kt @@ -4,6 +4,5 @@ import kotlinx.serialization.Serializable @Serializable data class GoogleLoginRequest( - val identityToken: String, val email: String ) diff --git a/core/network/src/main/java/com/goalpanzi/mission_mate/core/network/service/LoginService.kt b/core/network/src/main/java/com/goalpanzi/mission_mate/core/network/service/LoginService.kt index e7a8d184..216085b1 100644 --- a/core/network/src/main/java/com/goalpanzi/mission_mate/core/network/service/LoginService.kt +++ b/core/network/src/main/java/com/goalpanzi/mission_mate/core/network/service/LoginService.kt @@ -2,6 +2,7 @@ package com.goalpanzi.mission_mate.core.network.service import com.luckyoct.core.model.GoogleLogin import com.luckyoct.core.model.request.GoogleLoginRequest +import retrofit2.Response import retrofit2.http.Body import retrofit2.http.POST @@ -10,5 +11,5 @@ interface LoginService { @POST("/api/auth/login/google") suspend fun requestGoogleLogin( @Body request: GoogleLoginRequest - ): GoogleLogin + ): Response } \ No newline at end of file diff --git a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginEvent.kt b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginEvent.kt index d447417d..4b2edbb4 100644 --- a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginEvent.kt +++ b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginEvent.kt @@ -2,5 +2,5 @@ package com.goalpanzi.mission_mate.feature.login sealed interface LoginEvent { data object Error : LoginEvent - data class Success(val isAlreadyMember: Boolean) : LoginEvent + data class Success(val isProfileSet: Boolean) : LoginEvent } \ No newline at end of file diff --git a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginScreen.kt b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginScreen.kt index dd504e50..a3c2c212 100644 --- a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginScreen.kt +++ b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginScreen.kt @@ -43,7 +43,7 @@ fun LoginRoute( viewModel.eventFlow.collectLatest { when (it) { LoginEvent.Error -> Unit - is LoginEvent.Success -> onLoginSuccess(it.isAlreadyMember) + is LoginEvent.Success -> onLoginSuccess(it.isProfileSet) } } } diff --git a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginViewModel.kt b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginViewModel.kt index 36e4d4c4..015bc689 100644 --- a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginViewModel.kt +++ b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/LoginViewModel.kt @@ -8,7 +8,6 @@ import androidx.credentials.GetCredentialResponse import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.goalpanzi.mission_mate.core.domain.usecase.LoginUseCase -import com.goalpanzi.mission_mate.feature.login.util.TokenUtil import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException @@ -51,14 +50,15 @@ class LoginViewModel @Inject constructor( is CustomCredential -> { if (credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) { try { - val googleIdTokenCredential = - GoogleIdTokenCredential.createFrom(credential.data) - val compressedToken = TokenUtil.compressToken(googleIdTokenCredential.idToken) - val result = loginUseCase.requestGoogleLogin( - token = compressedToken, - email = googleIdTokenCredential.id + val googleIdTokenCredential = GoogleIdTokenCredential.createFrom(credential.data) + val result = loginUseCase.requestGoogleLogin(email = googleIdTokenCredential.id) + _eventFlow.emit( + result?.let { + LoginEvent.Success(it.isProfileSet) + } ?: run { + LoginEvent.Error + } ) - _eventFlow.emit(LoginEvent.Success(result.isProfileSet)) } catch (e: GoogleIdTokenParsingException) { e.printStackTrace() } diff --git a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/util/TokenUtil.kt b/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/util/TokenUtil.kt deleted file mode 100644 index 6b87dc6f..00000000 --- a/feature/login/src/main/java/com/goalpanzi/mission_mate/feature/login/util/TokenUtil.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.goalpanzi.mission_mate.feature.login.util - -import java.security.MessageDigest - -object TokenUtil { - fun compressToken(data: String): String { - val bytes = MessageDigest.getInstance("SHA-256").digest(data.toByteArray()) - return bytes.joinToString("") { "%02x".format(it) } - } -} \ No newline at end of file