-
Notifications
You must be signed in to change notification settings - Fork 0
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
[mod] 자동 로그인, 로그인 로직 수정 #171
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d316fcc
[mod] #170 자체 로그인 성공 여부에 대한 flow UiState로 감싸기
Dan2dani 30a612b
[mod] #170 내부 DB에 자동 로그인 여부를 설정하는 데이터 조작 로직 뷰모델로 이전
Dan2dani db5a852
[mod] #170 로그인 성공 시 내부 DB에 자동 로그인 여부를 true로
Dan2dani 428a590
[mod] #170 자동로그인 분기처리
Dan2dani 239c6f9
[feat] #170 인터셉터에 로그인 전까지는 authorization 안붙게 하기
Dan2dani 94dd48b
[feat] #170 회원가입에서 소셜이고 로그인인 경우에만 자동 로그인 설정이 되도록 구현
Dan2dani 1b5dff5
[feat] #170 자체 로그인 성공시 엑티비티 스택 비우기
Dan2dani fcd254d
[mod] #170 스플래시 뷰 보여준 후 화면 전환 되도록 수정
Dan2dani 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 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 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 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 |
---|---|---|
|
@@ -51,6 +51,7 @@ class SignActivity : | |
} | ||
|
||
AuthRoleType.USER -> { | ||
authViewModel.setAutoLogin() | ||
moveToMain() | ||
} | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope | |
import com.sopt.geonppang.data.datasource.local.GPDataSource | ||
import com.sopt.geonppang.data.model.request.RequestLogin | ||
import com.sopt.geonppang.domain.repository.AuthRepository | ||
import com.sopt.geonppang.util.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
@@ -19,26 +20,33 @@ class LogInViewModel @Inject constructor( | |
) : ViewModel() { | ||
val loginEmail = MutableStateFlow("") | ||
val loginPassword = MutableStateFlow("") | ||
private val _loginState = MutableStateFlow<Boolean?>(null) | ||
private val _loginState = MutableStateFlow<UiState<Boolean>>(UiState.Loading) | ||
val loginState get() = _loginState.asStateFlow() | ||
|
||
fun initLogin() { | ||
_loginState.value = null | ||
_loginState.value = UiState.Loading | ||
} | ||
|
||
fun setAutoLogin() { | ||
gpDataSource.isLogin = true | ||
} | ||
|
||
fun login() { | ||
viewModelScope.launch { | ||
authRepository.login(RequestLogin(loginEmail.value, loginPassword.value)) | ||
.onSuccess { loginResponse -> | ||
val responseHeader = loginResponse.headers() | ||
val accessToken = responseHeader[AUTHORIZATION].toString() | ||
val accessToken = responseHeader[AUTHORIZATION] | ||
val refreshToken = responseHeader[AUTHORIZATION_REFRESH] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refresh 도 해야하는지 생각을 못했다 .. 🐰 ❤️ |
||
if (loginResponse.code() == 200) { | ||
gpDataSource.accessToken = BEARER_PREFIX + accessToken | ||
gpDataSource.refreshToken = BEARER_PREFIX + refreshToken | ||
gpDataSource.isLogin = true | ||
_loginState.value = true | ||
_loginState.value = UiState.Success(true) | ||
setAutoLogin() | ||
} | ||
if (loginResponse.code() == 400) { | ||
_loginState.value = false | ||
_loginState.value = UiState.Error(loginResponse.message()) | ||
} | ||
if (loginResponse.code() == 500) { | ||
Timber.tag("서버 오류") | ||
|
@@ -51,6 +59,7 @@ class LogInViewModel @Inject constructor( | |
|
||
companion object { | ||
const val AUTHORIZATION = "Authorization" | ||
const val AUTHORIZATION_REFRESH = "Authorization-refresh" | ||
const val BEARER_PREFIX = "Bearer " | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -6,10 +6,10 @@ import androidx.activity.viewModels | |
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.sopt.geonppang.R | ||
import com.sopt.geonppang.data.datasource.local.GPDataSource | ||
import com.sopt.geonppang.databinding.ActivityLoginBinding | ||
import com.sopt.geonppang.presentation.MainActivity | ||
import com.sopt.geonppang.presentation.auth.SignUpActivity | ||
import com.sopt.geonppang.presentation.home.HomeFragment | ||
import com.sopt.geonppang.util.UiState | ||
import com.sopt.geonppang.util.binding.BindingActivity | ||
import com.sopt.geonppang.util.extension.hideKeyboard | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
@@ -25,7 +25,6 @@ class LoginActivity : | |
binding.viewModel = viewModel | ||
binding.lifecycleOwner = this | ||
|
||
autoLogin() | ||
addListener() | ||
collectData() | ||
} | ||
|
@@ -45,11 +44,12 @@ class LoginActivity : | |
private fun collectData() { | ||
viewModel.loginState.flowWithLifecycle(lifecycle).onEach { loginState -> | ||
when (loginState) { | ||
true -> { | ||
is UiState.Success -> { | ||
moveToHome() | ||
viewModel.setAutoLogin() | ||
} | ||
|
||
false -> { | ||
is UiState.Error -> { | ||
showLoginFailDialog() | ||
viewModel.initLogin() | ||
} | ||
|
@@ -64,20 +64,16 @@ class LoginActivity : | |
} | ||
|
||
private fun moveToHome() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 짱이다 |
||
startActivity(Intent(this, HomeFragment::class.java)) | ||
val intent = Intent(this, MainActivity::class.java) | ||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK | ||
startActivity(intent) | ||
finish() | ||
} | ||
|
||
private fun moveToSignup() { | ||
startActivity(Intent(this, SignUpActivity::class.java)) | ||
} | ||
|
||
private fun autoLogin() { | ||
val gpDataSource = GPDataSource(this) | ||
if (gpDataSource.isLogin) | ||
moveToHome() | ||
} | ||
|
||
companion object { | ||
const val LOGIN_FAIL = "loginFail" | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복확인도 uistate 로 변경할까염
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조하염~~