Skip to content

Commit 0dbb4aa

Browse files
authored
fix(auth): Remove online check from getCurrentUser (#3122)
1 parent 908ed9e commit 0dbb4aa

File tree

4 files changed

+2
-24
lines changed

4 files changed

+2
-24
lines changed

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/SessionHelper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ internal object SessionHelper {
7777
)
7878
}
7979
}
80+
81+
internal fun CognitoUserPoolTokens.isValid() = SessionHelper.isValidTokens(this)

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/usecases/AuthUseCaseFactory.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ internal class AuthUseCaseFactory(
9393
)
9494

9595
fun getCurrentUser() = GetCurrentUserUseCase(
96-
fetchAuthSession = fetchAuthSession(),
9796
stateMachine = stateMachine
9897
)
9998

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/usecases/GetCurrentUserUseCase.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ package com.amplifyframework.auth.cognito.usecases
1818
import com.amplifyframework.auth.AuthUser
1919
import com.amplifyframework.auth.cognito.AuthStateMachine
2020
import com.amplifyframework.auth.cognito.requireSignedInState
21-
import com.amplifyframework.auth.exceptions.SessionExpiredException
22-
import com.amplifyframework.util.throwIf
2321

2422
internal class GetCurrentUserUseCase(
25-
private val fetchAuthSession: FetchAuthSessionUseCase,
2623
private val stateMachine: AuthStateMachine
2724
) {
2825
suspend fun execute(): AuthUser {
2926
val state = stateMachine.requireSignedInState()
30-
31-
// Throw exception if session is expired
32-
val result = fetchAuthSession.execute().userPoolTokensResult
33-
result.error.throwIf<SessionExpiredException>()
34-
3527
return AuthUser(
3628
state.signedInData.userId,
3729
state.signedInData.username

aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/usecases/GetCurrentUserUseCaseTest.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.amplifyframework.auth.cognito.usecases
1818
import com.amplifyframework.auth.cognito.AuthStateMachine
1919
import com.amplifyframework.auth.cognito.mockSignedInData
2020
import com.amplifyframework.auth.exceptions.InvalidStateException
21-
import com.amplifyframework.auth.exceptions.SessionExpiredException
2221
import com.amplifyframework.auth.exceptions.SignedOutException
2322
import com.amplifyframework.statemachine.codegen.states.AuthenticationState
2423
import io.kotest.assertions.throwables.shouldThrow
@@ -29,10 +28,6 @@ import kotlinx.coroutines.test.runTest
2928
import org.junit.Test
3029

3130
class GetCurrentUserUseCaseTest {
32-
private val fetchAuthSession: FetchAuthSessionUseCase = mockk {
33-
coEvery { execute().userPoolTokensResult.error } returns null
34-
}
35-
3631
private val stateMachine: AuthStateMachine = mockk {
3732
coEvery { getCurrentState().authNState } returns AuthenticationState.SignedIn(
3833
signedInData = mockSignedInData(username = "username", userId = "sub"),
@@ -41,7 +36,6 @@ class GetCurrentUserUseCaseTest {
4136
}
4237

4338
private val useCase = GetCurrentUserUseCase(
44-
fetchAuthSession = fetchAuthSession,
4539
stateMachine = stateMachine
4640
)
4741

@@ -68,13 +62,4 @@ class GetCurrentUserUseCaseTest {
6862
useCase.execute()
6963
}
7064
}
71-
72-
@Test
73-
fun `throws exception for expired session`() = runTest {
74-
val error = SessionExpiredException()
75-
coEvery { fetchAuthSession.execute().userPoolTokensResult.error } returns error
76-
shouldThrow<SessionExpiredException> {
77-
useCase.execute()
78-
} shouldBe error
79-
}
8065
}

0 commit comments

Comments
 (0)