-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebUI reopens after successful sign up #2968
Comments
Can you show sample code for how you are calling |
Sure! We have a single Activity with default launch options. // Manifest <application>
<activity
android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.smith" />
</intent-filter>
</activity>
</application> // UI @Composable
internal fun LoginScreen(
state: LoginUiState,
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
) {
val activity = LocalContext.current as Activity
Box(
modifier.fillMaxSize()
) {
when (state) {
LoginUiState.Loading, LoginUiState.LoginStarted -> Loading(Modifier.align(Alignment.Center))
is LoginUiState.Ready -> {
LaunchedEffect(Unit) {
state.startAuthentication(activity)
}
}
LoginUiState.LoggedIn -> LoggedIn(navigateBack = navigateBack)
LoginUiState.Failed -> LoginFailed(navigateBack = navigateBack)
}
}
} //ViewModel @Immutable
sealed interface LoginUiState {
@Stable
data object Loading : LoginUiState
@Stable
data class Ready(
val startAuthentication: suspend (activity: Activity) -> Unit,
) : LoginUiState
@Stable
data object LoginStarted : LoginUiState
@Stable
data object LoggedIn : LoginUiState
@Stable
data object Failed : LoginUiState
}
private enum class LoginResult {
None,
Started,
Success,
Failed
}
class LoginViewModel @Inject constructor() : ViewModel() {
private val signInState = MutableStateFlow(LoginResult.None)
val uiState = stateStream().stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(StateFlowTimeouts.SHARING),
LoginUiState.Loading
)
private fun stateStream(): Flow<LoginUiState> =
signInState
.map { loginResult ->
when (loginResult) {
LoginResult.None -> {
LoginUiState.Ready(
startAuthentication = { activity ->
loginStarted()
requireAuth().startAuthentication(activity)
}
)
}
LoginResult.Started -> LoginUiState.LoginStarted
LoginResult.Success -> LoginUiState.LoggedIn
LoginResult.Failed -> LoginUiState.Failed
}
}
private fun Authentication.startAuthentication(activity: Activity) {
viewModelScope.launch {
val result = Amplify.Auth.signInWithSocialWebUI(AuthProvider.custom("XYZ"), activity)
when (result) {
is AuthSignInResult -> {
if (result.isSignedIn) {
signInState.emit(LoginResult.Success)
} else {
signInState.emit(LoginResult.Failed)
}
}
else -> signInState.emit(LoginResult.Failed)
}
}
}
private fun loginStarted() {
viewModelScope.launch {
signInState.emit(LoginResult.Started)
}
}
} |
I can't replicate this but the only thing I'm curious about is the custom auth provider. Who is the provider? My suspicion is that it is related to that. In a test environment, do you have standard |
Sorry for the delay but I was away for the holidays. The provider is used to support legacy service users. This setup works on other platforms: iOS & web and used to work on Android |
@tylerjroach downgrading This got me thinking that the problem is in redirects. Could you point me to documentation about those? Do they need to match the package? |
Hi @dawidhyzy, redirects have always been required as far as I am aware. Redirects are what allows Amplify to capture the code from the browser to exchange for a valid Auth token within the client. The documentation for adding the redirect to the manifest is here: https://docs.amplify.aws/gen1/android/build-a-backend/auth/add-social-provider/#update-androidmanifestxml The redirect scheme within the manifest, just needs to match the redirect provided to the Amplify Auth service. |
We are creating I was debugging it more and I can see that JSONObject is escaping the redirect strings for example it contains |
Yes the string would need to be "com.smith://oauth" |
With the help of the Chrome inspection tool, I was able to find out that there was an error shown in the console that navigation was not possible. The problem was that we are using schema environment suffixes for different build variants. After defining the full schema per build variant the redirect works correctly. Is it possible to set a debug flag that would display such an error on the authentication page? That would help with debugging in the future. |
Thank you for the update. I'll mark this as a feature request to see if there is any type of logging info that we can provide when this happens. We don't have control of the web page from a client perspective so any messages would have to try and come within our logs. |
Before opening, please confirm:
Language and Async Model
Kotlin - Coroutines
Amplify Categories
Authentication
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
After a successful signup, the WebUI closes and then reopens.
I can see in my logs that I received a successful result.
I can also see logs from
AuthClient
Reproduction steps (if applicable)
No response
Code Snippet
// Put your code below this line.
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: