-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
Language and Async Model
Kotlin
Amplify Categories
Authentication
Gradle script dependencies
amplifyVersion = "2.27.3"
amplifyAuthenticatorVersion = "1.4.3"Environment information
------------------------------------------------------------
Gradle 8.11.1
------------------------------------------------------------
Build time: 2024-11-20 16:56:46 UTC
Revision: 481cb05a490e0ef9f8620f7873b83bd8a72e7c39
Kotlin: 2.0.20
Groovy: 3.0.22
Ant: Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM: 17.0.4 (Amazon.com Inc. 17.0.4+8-LTS)
Daemon JVM: /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home (no JDK specified, using current Java home)
OS: Mac OS X 15.4.1 aarch64
Please include any relevant guides or documentation you're referencing
https://docs.amplify.aws/android/build-a-backend/auth/sign-in-with-web-ui/
Describe the bug
While the context below is more relevant to the amplify-ui-android repository, the solution requires understanding of the authentication state management in this amplify-android repository. Feel free to move this issue as you see fit.
I created a button in the signInContent of the Authenticator that calls Amplify.Auth.signInWithSocialWebUI to sign in with google. The sign in succeeds, but the Authenticator's state is still SignInStateImpl, not SignedInStateImpl. This causes my app's contents to still be behind the login screen. If I force quit the app and restart, the re-initialization of viewModel allows the state to check if the user is logged in again, finally showing the app's contents.
Swift had a similar issue. In Swift's case, I used a state variable that toggles on successful social sign in, allowing the authorizer to refresh. This does not work for Android since Authenticator remembers the old viewModel throughout the app's session.
There are two possible fixes to this bug:
- Provide a way for me to signal to the
AuthStateMachinethat it should enter theSignedInStateupon successful social sign in. - Or provide a way for me to completely re-initialize the
viewModelso that theviewModelcan pick up the fact that the user is now signed in. This is what I used in Swift
Reproduction steps (if applicable)
- Create an
Authorizerwith a button that signs in with google in theAuthorizer'ssignInContent
Amplify.Auth.signInWithSocialWebUI(
AuthProvider.google(),
this,
{
Log.i(
"KanaiAuth",
"Sign in with Google succeeded: $it"
)
},
{ Log.e("KanaiAuth", "Sign in with Google failed", it) }
)- Notice that the authorizer logs success, but the log in screen still shows
- Notice that if you force quit the app and enter it again, the app's contents now show.
Code Snippet
Authenticator(
state = newState,
signInContent = { state ->
CustomSignIn( // My sign in button that runs onGoogleSignIn
state = state,
onGoogleSignIn = {
// Sign in with Google using Amplify
Amplify.Auth.signInWithSocialWebUI(
AuthProvider.google(),
this,
{
Log.i(
"KanaiAuth",
"Sign in with Google succeeded: $it"
)
},
{ Log.e("KanaiAuth", "Sign in with Google failed", it) }
)
}
)
}
) { state ->
HomeScreen(state)
}Log output
Sign in with Google succeeded: AuthSignInResult{isSignedIn=true, nextStep=AuthNextSignInStep{signInStep=DONE, additionalInfo={}, codeDeliveryDetails=null, totpSetupDetails=null, allowedMFATypes=null, availableFactors=null}}
Configuration File
No response
GraphQL Schema
No response
Additional information and screenshots
No response