refactor: Don't request a new access token unless needed

This commit is contained in:
Peter Vacho 2024-12-24 00:38:26 +01:00
parent a4890a1bb3
commit 8f20cabb33
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -57,9 +57,12 @@ class MainActivity : AppCompatActivity() {
private suspend fun checkUserLogin(): Boolean {
if (authRepository.validateRefreshToken() != null) {
// Get a brand new access token (even if the old access token is still valid,
// it's better to just get a new one so it doesn't expire as quickly on us)
return authRepository.refreshAccessToken()
if (authRepository.validateAccessToken() == null) {
// In case access token is already invalid, request a new one
return authRepository.refreshAccessToken()
}
// Access token still valid, we're already logged in
return true
}
return false
}