-
Notifications
You must be signed in to change notification settings - Fork 119
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 |
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: