Skip to content

Commit

Permalink
[feat/#122] 구글로그인 구현중..
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed Aug 28, 2024
1 parent 8b1e59d commit 6217752
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ class KakaoSignupActivity : BaseActivity<FragmentKakaoSignupBinding>({
}
}

signUpViewModel.googleToken.observe(this) { token ->
if (token.isNotEmpty()) {
Intent(this, NicknameInputActivity::class.java).apply {
putExtra("googleToken", token)
when (val data = handleIntentExtra()) {
is SchemeState.NavReview -> {
putExtra(SchemeKey.NAV_REVIEW, data)
}
is SchemeState.NavReviewDetail -> {
putExtra(SchemeKey.NAV_REVIEW_DETAIL, data)
}
else -> Unit
}
startActivity(this)
}
}
}

signUpViewModel.loginUiState.asLiveData().observe(this) { state ->
when (state) {
LoginUiState.LoginSuccess -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class NicknameInputActivity: BaseActivity<FragmentNicknameInputBinding>({
NicknameInputState.NICKNAME_SUCCESS -> {
Intent(this@NicknameInputActivity, TeamSelectActivity::class.java).apply {
putExtra("nickname", etProfileEditNickname.text.toString())
putExtra("kakaoToken", intent.getStringExtra("kakaoToken"))
intent.getStringExtra("googleToken")?.let {
putExtra("googleToken", it)
} ?: run {
putExtra("kakaoToken", intent.getStringExtra("kakaoToken"))
}
when (val data = handleIntentExtra()) {
is SchemeState.NavReview -> {
putExtra(SchemeKey.NAV_REVIEW, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,17 @@ class TeamSelectActivity: BaseActivity<FragmentTeamSelectBinding>(
}

binding.tvSelectedTeamNextBtn.setOnClickListener {
signupViewModel.signUp(
intent.getStringExtra("kakaoToken") ?: "",
intent.getStringExtra("nickname") ?: ""
)
intent.getStringExtra("googleToken")?.let {
signupViewModel.signUpV2(
it,
intent.getStringExtra("nickname") ?: ""
)
} ?: run {
signupViewModel.signUp(
intent.getStringExtra("kakaoToken") ?: "",
intent.getStringExtra("nickname") ?: ""
)
}
}

binding.tvProfileEditNoTeam.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class KakaoSignupViewModel @Inject constructor(
private val _kakaoToken = MutableLiveData<String>()
val kakaoToken: LiveData<String> = _kakaoToken

private val _googleToken = MutableLiveData<String>()
val googleToken: LiveData<String> = _googleToken

private val _loginUiState = MutableStateFlow<LoginUiState>(LoginUiState.Initial)
val loginUiState: StateFlow<LoginUiState> = _loginUiState.asStateFlow()

Expand Down Expand Up @@ -57,13 +60,13 @@ class KakaoSignupViewModel @Inject constructor(
signupRepository.getSignupV2("GOOGLE", token)
.onSuccess {
if (it.jwtToken.isEmpty()) {
_kakaoToken.value = token
_googleToken.value = token
} else {
sharedPreference.token = it.jwtToken
_loginUiState.emit(LoginUiState.LoginSuccess)
}
}.onFailure {
_kakaoToken.value = token
_googleToken.value = token
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ class SignUpViewModel @Inject constructor(
}
}

fun signUpV2(
googleToken: String,
currentNickName: String
) {
viewModelScope.launch {
signupRepository.postSignup(
PostSignupModel(
idCode = googleToken,
nickname = currentNickName,
teamId = cheerTeam.value
)
).onSuccess {
sharedPreference.token = it.jwtToken
sharedPreference.nickname = currentNickName
_teamSelectUiState.emit(SignupUiState.SignUpSuccess(currentNickName))
}.onFailure {
_teamSelectUiState.emit(SignupUiState.Failure)
}
}
}

fun setClickedBaseballTeam(id: Int) {
val currentState = team.value
if (currentState is UiState.Success) {
Expand Down

0 comments on commit 6217752

Please sign in to comment.