Skip to content

Commit 2a9a162

Browse files
committed
Added suggested optimizations
1 parent 390d090 commit 2a9a162

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

Shrine/app/src/main/java/com/authentication/shrine/repository/AuthRepository.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,15 @@ class AuthRepository @Inject constructor(
442442
suspend fun isSessionIdValid(): Boolean {
443443
val sessionId = dataStore.read(SESSION_ID)
444444
if (!sessionId.isNullOrBlank()) {
445-
val apiResult = authApiService.getKeys(
446-
cookie = sessionId.createCookieHeader(),
447-
)
448-
if (apiResult.isSuccessful) {
449-
return true
445+
try {
446+
val apiResult = authApiService.getKeys(
447+
cookie = sessionId.createCookieHeader(),
448+
)
449+
if (apiResult.isSuccessful) {
450+
return true
451+
}
452+
} catch (e: ApiException) {
453+
Log.e(TAG, "Cannot call getKeys for isSessionIdValid")
450454
}
451455
}
452456

Shrine/app/src/main/java/com/authentication/shrine/ui/viewmodel/SplashViewModel.kt

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SplashViewModel @Inject constructor(
4343
init {
4444
viewModelScope.launch {
4545
val startDestination =
46-
if (isSessionIdValid() && (isSignedInThroughPassword() || isSignedInThroughPasskeys())) {
46+
if (isSessionIdValid()) {
4747
ShrineAppDestinations.MainMenuRoute.name
4848
} else {
4949
signOut()
@@ -59,30 +59,6 @@ class SplashViewModel @Inject constructor(
5959
}
6060
}
6161

62-
/**
63-
* Checks if the user is signed in using a password.
64-
*
65-
* This method checks if the user is signed in by calling the `isSignedIn()` method of the
66-
* [AuthRepository].
67-
*
68-
* @return True if the user is signed in using a password, false otherwise.
69-
*/
70-
private suspend fun isSignedInThroughPassword(): Boolean {
71-
return repository.isSignedInThroughPassword()
72-
}
73-
74-
/**
75-
* Checks if the user is signed in using passkeys.
76-
*
77-
* This method checks if the user is signed in through passkeys by calling the
78-
* `isSignedInThroughPasskeys()` method of the [AuthRepository].
79-
*
80-
* @return True if the user is signed in using passkeys, false otherwise.
81-
*/
82-
private suspend fun isSignedInThroughPasskeys(): Boolean {
83-
return repository.isSignedInThroughPasskeys()
84-
}
85-
8662
/**
8763
* Checks if the session ID is valid with the server.
8864
*
@@ -95,7 +71,7 @@ class SplashViewModel @Inject constructor(
9571
/**
9672
* Signs out the user.
9773
*/
98-
fun signOut() {
74+
private fun signOut() {
9975
viewModelScope.launch {
10076
repository.signOut()
10177
}

0 commit comments

Comments
 (0)