-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: handle 2fa code in new login flow [WPB-15853] #3858
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
.../main/kotlin/com/wire/android/ui/newauthentication/code/NewLoginVerificationCodeScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.newauthentication.login.code | ||
|
||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.text.input.TextFieldState | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.ramcosta.composedestinations.annotation.RootNavGraph | ||
import com.wire.android.R | ||
import com.wire.android.navigation.Navigator | ||
import com.wire.android.navigation.WireDestination | ||
import com.wire.android.navigation.style.AuthSlideNavigationAnimation | ||
import com.wire.android.ui.authentication.login.LoginState | ||
import com.wire.android.ui.authentication.login.WireAuthBackgroundLayout | ||
import com.wire.android.ui.authentication.login.email.LoginButton | ||
import com.wire.android.ui.authentication.login.email.LoginEmailViewModel | ||
import com.wire.android.ui.authentication.verificationcode.VerificationCode | ||
import com.wire.android.ui.authentication.verificationcode.VerificationCodeState | ||
import com.wire.android.ui.common.dimensions | ||
import com.wire.android.ui.common.preview.EdgeToEdgePreview | ||
import com.wire.android.ui.common.textfield.clearAutofillTree | ||
import com.wire.android.ui.newauthentication.login.NewLoginContainer | ||
import com.wire.android.ui.newauthentication.login.NewLoginHeader | ||
import com.wire.android.ui.newauthentication.login.NewLoginSubtitle | ||
import com.wire.android.ui.newauthentication.login.NewLoginTitle | ||
import com.wire.android.ui.newauthentication.login.password.LoginStateNavigationAndDialogs | ||
import com.wire.android.ui.theme.WireTheme | ||
import com.wire.android.ui.theme.wireDimensions | ||
import com.wire.android.util.ui.PreviewMultipleThemes | ||
|
||
@RootNavGraph | ||
@WireDestination( | ||
style = AuthSlideNavigationAnimation::class, | ||
) | ||
@Composable | ||
// has to be navigated to after NewLoginPasswordScreen, otherwise there will be illegal state because it needs to reuse view model from it | ||
fun NewLoginVerificationCodeScreen( | ||
navigator: Navigator, | ||
loginEmailViewModel: LoginEmailViewModel, // provided in MainNavHost to reuse from NewLoginPasswordScreen, don't use hiltViewModel() | ||
) { | ||
clearAutofillTree() | ||
LoginStateNavigationAndDialogs(loginEmailViewModel, navigator) | ||
|
||
LaunchedEffect(loginEmailViewModel) { | ||
loginEmailViewModel.autoLoginWhenFullCodeEntered = false | ||
} | ||
|
||
val navigateBack = { | ||
loginEmailViewModel.onCodeVerificationBackPress() | ||
navigator.navigateBack() | ||
} | ||
BackHandler { | ||
navigateBack() | ||
} | ||
|
||
LoginVerificationCodeContent( | ||
codeTextState = loginEmailViewModel.secondFactorVerificationCodeTextState, | ||
codeState = loginEmailViewModel.secondFactorVerificationCodeState, | ||
isLoading = loginEmailViewModel.loginState.flowState is LoginState.Loading, | ||
onResendCode = loginEmailViewModel::onCodeResend, | ||
onLoginButtonClick = loginEmailViewModel::login, | ||
canNavigateBack = navigator.navController.previousBackStackEntry != null, // if there is a previous screen to navigate back to | ||
navigateBack = navigateBack, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun LoginVerificationCodeContent( | ||
codeTextState: TextFieldState, | ||
codeState: VerificationCodeState, | ||
isLoading: Boolean, | ||
onResendCode: () -> Unit, | ||
onLoginButtonClick: () -> Unit, | ||
canNavigateBack: Boolean, | ||
navigateBack: () -> Unit, | ||
) { | ||
NewLoginContainer( | ||
header = { | ||
NewLoginHeader( | ||
title = { | ||
NewLoginTitle( | ||
title = stringResource(R.string.enterprise_login_verification_code_title), | ||
modifier = Modifier.padding(bottom = dimensions().spacing24x) | ||
) | ||
NewLoginSubtitle( | ||
title = stringResource(R.string.second_factor_authentication_instructions_label, codeState.emailUsed), | ||
) | ||
}, | ||
canNavigateBack = canNavigateBack, | ||
onNavigateBack = navigateBack | ||
) | ||
} | ||
) { | ||
VerificationCode( | ||
codeLength = codeState.codeLength, | ||
codeState = codeTextState, | ||
isLoading = isLoading, | ||
showLoadingProgress = false, // for new login we show progress on the "next" button | ||
isCurrentCodeInvalid = codeState.isCurrentCodeInvalid, | ||
onResendCode = onResendCode, | ||
modifier = Modifier.padding(bottom = MaterialTheme.wireDimensions.spacing24x), | ||
) | ||
LoginButton( | ||
loading = isLoading, | ||
enabled = codeTextState.text.length == codeState.codeLength, | ||
text = stringResource(R.string.enterprise_login_next), | ||
loadingText = stringResource(R.string.enterprise_login_next), | ||
onClick = onLoginButtonClick, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(bottom = dimensions().spacing8x), | ||
) | ||
} | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
private fun PreviewNewLoginVerificationCodeScreen() = WireTheme { | ||
EdgeToEdgePreview(useDarkIcons = false) { | ||
WireAuthBackgroundLayout { | ||
LoginVerificationCodeContent( | ||
codeTextState = TextFieldState(), | ||
codeState = VerificationCodeState( | ||
codeLength = 6, | ||
isCurrentCodeInvalid = false, | ||
emailUsed = "" | ||
), | ||
isLoading = false, | ||
onResendCode = {}, | ||
onLoginButtonClick = {}, | ||
canNavigateBack = true, | ||
navigateBack = {}, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't here be only 1 NewLoginSubtitle? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just for the preview to simulate situation when there are multiple texts inside the
NewLoginHeader
to make sure that the navigation icon button is placed properly 😃