-
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
fix: 토큰 401 에러 해결 #562
fix: 토큰 401 에러 해결 #562
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,11 +91,13 @@ class AuthRepository @Inject constructor( | |
refreshToken = response.refreshToken | ||
response.authorization | ||
}.getOrElse { | ||
|
||
it.printStackTrace() | ||
null | ||
} | ||
} | ||
|
||
|
||
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. 🚫 [ktlint] standard:no-consecutive-blank-lines reported by reviewdog 🐶 |
||
fun updateAccessToken(accessToken: String) { | ||
this.accessToken = accessToken | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ class VersionRepository @Inject constructor( | |
companion object { | ||
private const val OS = "android" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.into.websoso.data.repository.AuthRepository | ||
import com.into.websoso.data.repository.UserRepository | ||
import com.into.websoso.data.repository.VersionRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
|
@@ -14,12 +15,46 @@ import javax.inject.Inject | |
class SplashViewModel @Inject constructor( | ||
private val authRepository: AuthRepository, | ||
private val versionRepository: VersionRepository, | ||
private val userRepository: UserRepository, | ||
) : ViewModel() { | ||
private val _isUpdateRequired: MutableLiveData<Boolean> = MutableLiveData() | ||
val isUpdateRequired: LiveData<Boolean> get() = _isUpdateRequired | ||
|
||
private var _isAutoLogin = MutableLiveData(false) | ||
private var _isAutoLogin: MutableLiveData<Boolean> = MutableLiveData() | ||
val isAutoLogin: LiveData<Boolean> get() = _isAutoLogin | ||
|
||
fun autoLogin() { | ||
private var _error: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val error: LiveData<Boolean> get() = _error | ||
|
||
init { | ||
checkAndUpdateVersion() | ||
} | ||
|
||
private fun checkAndUpdateVersion() { | ||
viewModelScope.launch { | ||
runCatching { | ||
versionRepository.isUpdateRequired() | ||
}.onSuccess { isRequired -> | ||
_isUpdateRequired.value = isRequired | ||
} | ||
} | ||
} | ||
|
||
/* 토큰 만료 확인용 - 추후 로직 수정 필요 */ | ||
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. 🚫 [ktlint] standard:no-single-line-block-comment reported by reviewdog 🐶 |
||
fun updateMyProfile() { | ||
viewModelScope.launch { | ||
runCatching { | ||
userRepository.fetchMyProfile() | ||
}.onSuccess { | ||
autoLogin() | ||
}.onFailure { | ||
authRepository.clearTokens() | ||
_error.value = true | ||
} | ||
} | ||
} | ||
|
||
private fun autoLogin() { | ||
viewModelScope.launch { | ||
if (authRepository.isAutoLogin) { | ||
runCatching { | ||
|
@@ -34,16 +69,4 @@ class SplashViewModel @Inject constructor( | |
} | ||
} | ||
} | ||
|
||
fun updateMinimumVersion(onUpdateRequired: (Boolean) -> Unit) { | ||
viewModelScope.launch { | ||
runCatching { | ||
versionRepository.isUpdateRequired() | ||
}.onSuccess { isUpdateRequired -> | ||
onUpdateRequired(isUpdateRequired) | ||
}.onFailure { | ||
onUpdateRequired(false) | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
🚫 [ktlint] standard:no-empty-first-line-in-method-block reported by reviewdog 🐶
First line in a method block should not be empty