-
Notifications
You must be signed in to change notification settings - Fork 1
구글 로그인 기능 구현 #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
구글 로그인 기능 구현 #61
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
43b0337
Merge branch 'develop' into feat/#57-google-login
chanho0908 558ef83
✨ Feat: data 모듈에 core:token 모듈 의존성 추가
chanho0908 351eae9
✨ Feat: 구글 로그인 라이브러리 추가
chanho0908 844b990
✨ Feat: 로그인 타입을 나타내는 `LoginType` enum 클래스 추가
chanho0908 a599f2b
✨Feat: Google 로그인 API endpoint 수정
chanho0908 9e9301f
✨ Feat: 소셜 로그인 Repository 구현
chanho0908 920e1a4
♻️ Refactor: 로그인 요청 파라미터 수정
chanho0908 865e20f
✨ Feat: AuthRepository 의존성 주입 추가
chanho0908 2393528
✨ Feat: 소셜로그인 기능 추상화
chanho0908 d9a2e47
✨ Feat: Google 로그인 기능 구현
chanho0908 081d61e
✨ Feat: 로그인 버튼 컴포넌트 추가
chanho0908 2cd9375
✨ Feat: 로그인 화면 구현
chanho0908 9fccb28
✨ Feat: 로그인 성공 시 홈 화면으로 이동
chanho0908 88060b7
♻️ Refactor: 시작 화면을 로그인으로 변경
chanho0908 ed1e338
♻️ Refactor: LoginProviderFactory를 domain 모듈에서 feature/login 모듈로 이동
chanho0908 755644e
✨ Feat: CI 워크플로우에 `GOOGLE_CLIENT_ID` 추가
chanho0908 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="16dp" | ||
| android:height="16dp" | ||
| android:viewportWidth="16" | ||
| android:viewportHeight="16"> | ||
| <path | ||
| android:pathData="M15.028,7.842C15.028,7.298 14.979,6.775 14.889,6.273H7.668V9.239H11.794C11.616,10.197 11.076,11.009 10.264,11.553V13.477H12.742C14.192,12.142 15.028,10.177 15.028,7.842Z" | ||
| android:fillColor="#4285F4" | ||
| android:fillType="evenOdd"/> | ||
| <path | ||
| android:pathData="M7.668,15.333C9.738,15.333 11.473,14.646 12.742,13.476L10.264,11.552C9.577,12.012 8.699,12.284 7.668,12.284C5.671,12.284 3.981,10.935 3.378,9.123H0.816V11.109C2.078,13.615 4.671,15.333 7.668,15.333Z" | ||
| android:fillColor="#34A853" | ||
| android:fillType="evenOdd"/> | ||
| <path | ||
| android:pathData="M3.377,9.124C3.223,8.664 3.136,8.173 3.136,7.668C3.136,7.162 3.223,6.671 3.377,6.211V4.225H0.815C0.296,5.26 0,6.431 0,7.668C0,8.905 0.296,10.076 0.815,11.111L3.377,9.124Z" | ||
| android:fillColor="#FBBC05" | ||
| android:fillType="evenOdd"/> | ||
| <path | ||
| android:pathData="M7.668,3.049C8.793,3.049 9.804,3.436 10.598,4.196L12.797,1.997C11.47,0.76 9.734,0 7.668,0C4.671,0 2.078,1.718 0.816,4.224L3.378,6.21C3.981,4.398 5.671,3.049 7.668,3.049Z" | ||
| android:fillColor="#EA4335" | ||
| android:fillType="evenOdd"/> | ||
| </vector> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ android { | |
|
|
||
| dependencies { | ||
| implementation(projects.core.datastore) | ||
| implementation(projects.core.token) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
data/src/main/java/com/twix/data/repository/DefaultAuthRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.twix.data.repository | ||
|
|
||
| import com.twix.domain.login.LoginType | ||
| import com.twix.domain.repository.AuthRepository | ||
| import com.twix.network.model.request.LoginRequest | ||
| import com.twix.network.service.AuthService | ||
| import com.twix.token.TokenProvider | ||
|
|
||
| class DefaultAuthRepository( | ||
| private val service: AuthService, | ||
| private val tokenProvider: TokenProvider, | ||
| ) : AuthRepository { | ||
| override suspend fun login( | ||
| idToken: String, | ||
| type: LoginType, | ||
| ) { | ||
| val response = | ||
| when (type) { | ||
| LoginType.GOOGLE -> service.googleLogin(LoginRequest(idToken)) | ||
| LoginType.KAKAO -> return | ||
| } | ||
|
|
||
| tokenProvider.saveToken(response.accessToken, response.refreshToken) | ||
| } | ||
chanho0908 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.twix.domain.login | ||
|
|
||
| interface LoginProvider { | ||
| suspend fun login(): LoginResult | ||
|
|
||
| suspend fun logout(): Result<Unit> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.twix.domain.login | ||
|
|
||
| sealed interface LoginResult { | ||
| data class Success( | ||
| val idToken: String, | ||
| val type: LoginType, | ||
| ) : LoginResult | ||
|
|
||
| data object Cancel : LoginResult | ||
|
|
||
| data class Failure( | ||
| val throwable: Throwable?, | ||
| ) : LoginResult | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.twix.domain.login | ||
|
|
||
| enum class LoginType { | ||
| GOOGLE, | ||
| KAKAO, | ||
| } |
10 changes: 10 additions & 0 deletions
10
domain/src/main/java/com/twix/domain/repository/AuthRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.twix.domain.repository | ||
|
|
||
| import com.twix.domain.login.LoginType | ||
|
|
||
| interface AuthRepository { | ||
| suspend fun login( | ||
| idToken: String, | ||
| type: LoginType, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,35 @@ | ||
| import java.util.Properties | ||
| import kotlin.apply | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.twix.feature) | ||
| } | ||
|
|
||
| val localProperties = | ||
| Properties().apply { | ||
| val localPropertiesFile = rootProject.file("local.properties") | ||
| if (localPropertiesFile.exists()) { | ||
| load(localPropertiesFile.inputStream()) | ||
| } | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.twix.login" | ||
|
|
||
| buildFeatures { | ||
| buildConfig = true | ||
| } | ||
|
|
||
| defaultConfig { | ||
| buildConfigField( | ||
| "String", | ||
| "GOOGLE_CLIENT_ID", | ||
| "\"${localProperties.getProperty("google_client_id")}\"", | ||
| ) | ||
chanho0908 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| dependencies { | ||
| implementation(libs.googleid) | ||
| implementation(libs.androidx.credentials) | ||
| implementation(libs.androidx.credentials.play.services.auth) | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
feature/login/src/main/java/com/twix/login/LoginProviderFactory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.twix.login | ||
|
|
||
| import com.twix.domain.login.LoginProvider | ||
| import com.twix.domain.login.LoginType | ||
|
|
||
| class LoginProviderFactory( | ||
| private val providers: Map<LoginType, LoginProvider>, | ||
| ) { | ||
| operator fun get(type: LoginType): LoginProvider = | ||
| providers[type] | ||
| ?: throw IllegalArgumentException(UNSUPPORTED_LOGIN_TYPE.format(type)) | ||
|
|
||
| companion object { | ||
| private const val UNSUPPORTED_LOGIN_TYPE = "Unsupported login type: %s" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,84 @@ | ||
| package com.twix.login | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.rememberCoroutineScope | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.twix.designsystem.components.toast.ToastManager | ||
| import com.twix.designsystem.components.toast.model.ToastData | ||
| import com.twix.designsystem.components.toast.model.ToastType | ||
| import com.twix.designsystem.theme.TwixTheme | ||
| import com.twix.domain.login.LoginType | ||
| import com.twix.login.LoginProviderFactory | ||
| import com.twix.login.component.LoginButton | ||
| import com.twix.login.model.LoginIntent | ||
| import com.twix.login.model.LoginSideEffect | ||
| import com.twix.ui.base.ObserveAsEvents | ||
| import kotlinx.coroutines.launch | ||
| import org.koin.androidx.compose.koinViewModel | ||
| import org.koin.compose.koinInject | ||
|
|
||
| @Composable | ||
| fun LoginScreen() { | ||
| LoginContent() | ||
| fun LoginRoute( | ||
| navigateToHome: () -> Unit, | ||
| navigateToOnBoarding: () -> Unit, | ||
| toastManager: ToastManager = koinInject(), | ||
| loginProvider: LoginProviderFactory = koinInject(), | ||
| viewModel: LoginViewModel = koinViewModel(), | ||
| ) { | ||
| val coroutineScope = rememberCoroutineScope() | ||
|
|
||
| val loginFailMessage = stringResource(R.string.login_fail_message) | ||
| ObserveAsEvents(viewModel.sideEffect) { sideEffect -> | ||
| when (sideEffect) { | ||
| LoginSideEffect.NavigateToHome -> navigateToHome() | ||
| LoginSideEffect.NavigateToOnBoarding -> navigateToOnBoarding() | ||
| LoginSideEffect.ShowLoginFailToast -> { | ||
| toastManager.tryShow(ToastData(loginFailMessage, ToastType.ERROR)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| LoginScreen { type -> | ||
| coroutineScope.launch { | ||
| viewModel.dispatch(LoginIntent.Login(loginProvider[type].login())) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun LoginContent() { | ||
| private fun LoginScreen(onClickLogin: (LoginType) -> Unit) { | ||
| Box( | ||
| modifier = Modifier.fillMaxSize(), | ||
| contentAlignment = Alignment.Center, | ||
| ) { | ||
| Text("임시 화면입니다.") | ||
| Column( | ||
| modifier = | ||
| Modifier | ||
| .fillMaxWidth() | ||
| .padding(horizontal = 20.dp), | ||
| verticalArrangement = Arrangement.spacedBy(12.dp), | ||
| ) { | ||
| // LoginType.entries.forEach { type -> | ||
| LoginButton(type = LoginType.GOOGLE, onClickLogin = onClickLogin) | ||
| // } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun LoginScreenPreview() { | ||
| TwixTheme { | ||
| LoginScreen(onClickLogin = {}) | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
feature/login/src/main/java/com/twix/login/LoginViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.twix.login | ||
|
|
||
| import androidx.lifecycle.viewModelScope | ||
| import com.twix.domain.login.LoginResult | ||
| import com.twix.domain.repository.AuthRepository | ||
| import com.twix.login.model.LoginIntent | ||
| import com.twix.login.model.LoginSideEffect | ||
| import com.twix.login.model.LoginUiState | ||
| import com.twix.ui.base.BaseViewModel | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| class LoginViewModel( | ||
| private val authRepository: AuthRepository, | ||
| ) : BaseViewModel<LoginUiState, LoginIntent, LoginSideEffect>(LoginUiState()) { | ||
| override suspend fun handleIntent(intent: LoginIntent) { | ||
| when (intent) { | ||
| is LoginIntent.Login -> login(intent.result) | ||
| } | ||
| } | ||
|
|
||
| private fun login(result: LoginResult) { | ||
| viewModelScope.launch { | ||
| when (result) { | ||
| is LoginResult.Success -> { | ||
| authRepository.login(result.idToken, result.type) | ||
| emitSideEffect(LoginSideEffect.NavigateToHome) | ||
| } | ||
| is LoginResult.Failure -> { | ||
| emitSideEffect(LoginSideEffect.ShowLoginFailToast) | ||
| } | ||
chanho0908 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LoginResult.Cancel -> Unit | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.