Skip to content
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

Add a couple more error messages during authentication. #2497

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
"screen_change_account_provider_subtitle" = "Use a different account provider, such as your own private server or a work account.";
"screen_change_account_provider_title" = "Change account provider";
"screen_change_server_error_invalid_homeserver" = "We couldn't reach this homeserver. Please check that you have entered the homeserver URL correctly. If the URL is correct, contact your homeserver administrator for further help.";
"screen_change_server_error_invalid_well_known" = "Sliding sync isn't available due to an issue in the well-known file:\n%1$@";
"screen_change_server_error_no_sliding_sync_message" = "This server currently doesn’t support sliding sync.";
"screen_change_server_form_header" = "Homeserver URL";
"screen_change_server_form_notice" = "You can only connect to an existing server that supports sliding sync. Your homeserver admin will need to configure it. %1$@";
Expand Down Expand Up @@ -406,6 +407,7 @@
"screen_login_error_deactivated_account" = "This account has been deactivated.";
"screen_login_error_invalid_credentials" = "Incorrect username and/or password";
"screen_login_error_invalid_user_id" = "This is not a valid user identifier. Expected format: ‘@user:homeserver.org’";
"screen_login_error_refresh_tokens" = "This server is configured to use refresh tokens. These aren't supported when using password based login.";
"screen_login_error_unsupported_authentication" = "The selected homeserver doesn't support password or OIDC login. Please contact your admin or choose another homeserver.";
"screen_login_form_header" = "Enter your details";
"screen_login_title" = "Welcome back!";
Expand Down
7 changes: 7 additions & 0 deletions ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,11 @@ internal enum L10n {
internal static var screenChangeAccountProviderTitle: String { return L10n.tr("Localizable", "screen_change_account_provider_title") }
/// We couldn't reach this homeserver. Please check that you have entered the homeserver URL correctly. If the URL is correct, contact your homeserver administrator for further help.
internal static var screenChangeServerErrorInvalidHomeserver: String { return L10n.tr("Localizable", "screen_change_server_error_invalid_homeserver") }
/// Sliding sync isn't available due to an issue in the well-known file:
/// %1$@
internal static func screenChangeServerErrorInvalidWellKnown(_ p1: Any) -> String {
return L10n.tr("Localizable", "screen_change_server_error_invalid_well_known", String(describing: p1))
}
/// This server currently doesn’t support sliding sync.
internal static var screenChangeServerErrorNoSlidingSyncMessage: String { return L10n.tr("Localizable", "screen_change_server_error_no_sliding_sync_message") }
/// Homeserver URL
Expand Down Expand Up @@ -1010,6 +1015,8 @@ internal enum L10n {
internal static var screenLoginErrorInvalidCredentials: String { return L10n.tr("Localizable", "screen_login_error_invalid_credentials") }
/// This is not a valid user identifier. Expected format: ‘@user:homeserver.org’
internal static var screenLoginErrorInvalidUserId: String { return L10n.tr("Localizable", "screen_login_error_invalid_user_id") }
/// This server is configured to use refresh tokens. These aren't supported when using password based login.
internal static var screenLoginErrorRefreshTokens: String { return L10n.tr("Localizable", "screen_login_error_refresh_tokens") }
/// The selected homeserver doesn't support password or OIDC login. Please contact your admin or choose another homeserver.
internal static var screenLoginErrorUnsupportedAuthentication: String { return L10n.tr("Localizable", "screen_login_error_unsupported_authentication") }
/// Enter your details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ final class LoginScreenCoordinator: CoordinatorProtocol {
viewModel.displayError(.alert(L10n.screenLoginErrorInvalidCredentials))
case .accountDeactivated:
viewModel.displayError(.alert(L10n.screenLoginErrorDeactivatedAccount))
case .invalidWellKnown(let error):
viewModel.displayError(.invalidWellKnownAlert(error))
case .slidingSyncNotAvailable:
viewModel.displayError(.slidingSyncAlert)
case .sessionTokenRefreshNotSupported:
viewModel.displayError(.refreshTokenAlert)
default:
viewModel.displayError(.alert(L10n.errorUnknown))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ enum LoginScreenErrorType: Hashable {
case alert(String)
/// Looking up the homeserver from the username failed.
case invalidHomeserver
/// An alert that informs the user about a bad well-known file.
case invalidWellKnownAlert(String)
/// An alert that allows the user to learn about sliding sync.
case slidingSyncAlert
/// An alert that informs the user that login failed due to a refresh token being returned.
case refreshTokenAlert
/// The response from the homeserver was unexpected.
case unknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonError,
message: L10n.screenLoginErrorInvalidUserId)
case .invalidWellKnownAlert(let error):
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
title: L10n.commonServerNotSupported,
message: L10n.screenChangeServerErrorInvalidWellKnown(error))
case .slidingSyncAlert:
let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) }
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
Expand All @@ -76,6 +80,10 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc

// Clear out the invalid username to avoid an attempted login to matrix.org
state.bindings.username = ""
case .refreshTokenAlert:
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonServerNotSupported,
message: L10n.screenLoginErrorRefreshTokens)
case .unknown:
state.bindings.alertInfo = AlertInfo(id: type)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ final class ServerSelectionScreenCoordinator: CoordinatorProtocol {
switch error {
case .invalidServer, .invalidHomeserverAddress:
viewModel.displayError(.footerMessage(L10n.screenChangeServerErrorInvalidHomeserver))
case .invalidWellKnown(let error):
viewModel.displayError(.invalidWellKnownAlert(error))
case .slidingSyncNotAvailable:
viewModel.displayError(.slidingSyncAlert)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ enum ServerSelectionScreenViewAction {
enum ServerSelectionScreenErrorType: Hashable {
/// An error message to be shown in the text field footer.
case footerMessage(String)
/// An alert that informs the user about a bad well-known file.
case invalidWellKnownAlert(String)
/// An alert that allows the user to learn about sliding sync.
case slidingSyncAlert
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class ServerSelectionScreenViewModel: ServerSelectionScreenViewModelType, Server
withElementAnimation {
state.footerErrorMessage = message
}
case .invalidWellKnownAlert(let error):
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
title: L10n.commonServerNotSupported,
message: L10n.screenChangeServerErrorInvalidWellKnown(error))
case .slidingSyncAlert:
let openURL = { UIApplication.shared.open(self.slidingSyncLearnMoreURL) }
state.bindings.alertInfo = AlertInfo(id: .slidingSyncAlert,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
// No need to show an error, the user cancelled authentication.
break
case .sessionTokenRefreshNotSupported:
// We should display a specific error saying that we do not support this kind of login
// But the copy is TBD
viewModel.displayError(.alert(L10n.errorUnknown))
viewModel.displayError(.refreshTokenAlert)
default:
viewModel.displayError(.alert(L10n.errorUnknown))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ enum SoftLogoutScreenViewAction {
enum SoftLogoutScreenErrorType: Hashable {
/// A specific error message shown in an alert.
case alert(String)
/// An alert that informs the user that login failed due to a refresh token being returned.
case refreshTokenAlert
/// An unknown error occurred.
case unknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class SoftLogoutScreenViewModel: SoftLogoutScreenViewModelType, SoftLogoutScreen
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonError,
message: message)
case .refreshTokenAlert:
state.bindings.alertInfo = AlertInfo(id: type,
title: L10n.commonServerNotSupported,
message: L10n.screenLoginErrorRefreshTokens)
case .unknown:
state.bindings.alertInfo = AlertInfo(id: type)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {

homeserverSubject.send(homeserver)
return .success(())
} catch AuthenticationError.WellKnownDeserializationError(let error) {
MXLog.error("The user entered a server with an invalid well-known file: \(error)")
return .failure(.invalidWellKnown(error))
} catch AuthenticationError.SlidingSyncNotAvailable {
MXLog.info("User entered a homeserver that isn't configured for sliding sync.")
return .failure(.slidingSyncNotAvailable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum AuthenticationServiceError: Error {
case invalidServer
case invalidCredentials
case invalidHomeserverAddress
case invalidWellKnown(String)
case slidingSyncNotAvailable
case accountDeactivated
case failedLoggingIn
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-2497.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add error messages about refresh tokens and an invalid well-known file.
Loading