File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
main/java/com/amplifyframework/ui/authenticator
test/java/com/amplifyframework/ui/authenticator Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import com.amplifyframework.auth.cognito.exceptions.service.UserNotConfirmedExce
35
35
import com.amplifyframework.auth.cognito.exceptions.service.UserNotFoundException
36
36
import com.amplifyframework.auth.cognito.exceptions.service.UsernameExistsException
37
37
import com.amplifyframework.auth.exceptions.NotAuthorizedException
38
+ import com.amplifyframework.auth.exceptions.SessionExpiredException
38
39
import com.amplifyframework.auth.exceptions.UnknownException
39
40
import com.amplifyframework.auth.options.AuthSignUpOptions
40
41
import com.amplifyframework.auth.result.AuthResetPasswordResult
@@ -573,7 +574,17 @@ internal class AuthenticatorViewModel(
573
574
private suspend fun handleSignedIn () {
574
575
logger.debug(" Log in successful, getting current user" )
575
576
when (val result = authProvider.getCurrentUser()) {
576
- is AmplifyResult .Error -> handleGeneralFailure(result.error)
577
+ is AmplifyResult .Error -> {
578
+ if (result.error is SessionExpiredException ) {
579
+ logger.error(result.error.toString())
580
+ logger.error(" Current signed in user session has expired, signing out." )
581
+ signOut()
582
+ moveTo(AuthenticatorStep .SignIn )
583
+ } else {
584
+ handleGeneralFailure(result.error)
585
+ }
586
+ }
587
+
577
588
is AmplifyResult .Success -> moveTo(stateFactory.newSignedInState(result.data, this ::signOut))
578
589
}
579
590
}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import aws.smithy.kotlin.runtime.http.HttpException
20
20
import com.amplifyframework.auth.AuthUserAttributeKey.email
21
21
import com.amplifyframework.auth.AuthUserAttributeKey.emailVerified
22
22
import com.amplifyframework.auth.MFAType
23
+ import com.amplifyframework.auth.exceptions.SessionExpiredException
23
24
import com.amplifyframework.auth.exceptions.UnknownException
24
25
import com.amplifyframework.auth.result.AuthResetPasswordResult
25
26
import com.amplifyframework.auth.result.step.AuthNextResetPasswordStep
@@ -129,6 +130,21 @@ class AuthenticatorViewModelTest {
129
130
viewModel.currentStep shouldBe AuthenticatorStep .Error
130
131
}
131
132
133
+ @Test
134
+ fun `getCurrentUser error with session expired exception during start results in SignIn state` () = runTest {
135
+ coEvery { authProvider.fetchAuthSession() } returns Success (mockAuthSession(isSignedIn = true ))
136
+ coEvery { authProvider.getCurrentUser() } returns AmplifyResult .Error (SessionExpiredException ())
137
+
138
+ viewModel.start(mockAuthenticatorConfiguration())
139
+ advanceUntilIdle()
140
+
141
+ coVerify(exactly = 1 ) {
142
+ authProvider.fetchAuthSession()
143
+ authProvider.getCurrentUser()
144
+ }
145
+ viewModel.currentStep shouldBe AuthenticatorStep .SignIn
146
+ }
147
+
132
148
@Test
133
149
fun `when already signed in during start the initial state should be signed in` () = runTest {
134
150
coEvery { authProvider.fetchAuthSession() } returns Success (mockAuthSession(isSignedIn = true ))
You can’t perform that action at this time.
0 commit comments