From 5175f6e94b46af11b7fcd31665bbc604f9a23c56 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Tue, 27 Feb 2024 08:48:21 +0000 Subject: [PATCH] Add a couple more error messages during authentication. (#2497) * Add copy for error when signing in with refresh tokens enabled. * Show an error when a server's well-known file is invalid. * Changelog. * Fix wrong alert. --- .../LoginScreen/LoginScreenCoordinator.swift | 4 ++++ .../Authentication/LoginScreen/LoginScreenModels.swift | 4 ++++ .../Authentication/LoginScreen/LoginScreenViewModel.swift | 8 ++++++++ .../ServerSelectionScreenCoordinator.swift | 2 ++ .../ServerSelectionScreenModels.swift | 2 ++ .../ServerSelectionScreenViewModel.swift | 4 ++++ .../SoftLogoutScreen/SoftLogoutScreenCoordinator.swift | 4 +--- .../SoftLogoutScreen/SoftLogoutScreenModels.swift | 2 ++ .../SoftLogoutScreen/SoftLogoutScreenViewModel.swift | 4 ++++ .../Authentication/AuthenticationServiceProxy.swift | 3 +++ .../AuthenticationServiceProxyProtocol.swift | 1 + changelog.d/pr-2497.change | 1 + 12 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-2497.change diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift index 6b1c71dea..2001538e5 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenCoordinator.swift @@ -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)) } diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenModels.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenModels.swift index cb8013eae..b10dade64 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenModels.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenModels.swift @@ -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 } diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift index 990bc2119..b2f140136 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginScreenViewModel.swift @@ -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, @@ -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) } diff --git a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenCoordinator.swift index 79807d9bc..35cd1ffea 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenCoordinator.swift @@ -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: diff --git a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenModels.swift b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenModels.swift index 02be90fd4..03faa7014 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenModels.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenModels.swift @@ -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 } diff --git a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenViewModel.swift b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenViewModel.swift index 31f1da2af..258f11a74 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelectionScreen/ServerSelectionScreenViewModel.swift @@ -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, diff --git a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift index fc0617e6d..844df8816 100644 --- a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift @@ -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)) } diff --git a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenModels.swift b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenModels.swift index e75dc3ede..20b77998a 100644 --- a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenModels.swift +++ b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenModels.swift @@ -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 } diff --git a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenViewModel.swift b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenViewModel.swift index 8558f9580..bfac1d246 100644 --- a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenViewModel.swift +++ b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenViewModel.swift @@ -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) } diff --git a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift index 1c053b9d6..4dcb0a177 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift @@ -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) diff --git a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift index cf9a34f6b..a0b054a69 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift @@ -31,6 +31,7 @@ enum AuthenticationServiceError: Error { case invalidServer case invalidCredentials case invalidHomeserverAddress + case invalidWellKnown(String) case slidingSyncNotAvailable case accountDeactivated case failedLoggingIn diff --git a/changelog.d/pr-2497.change b/changelog.d/pr-2497.change new file mode 100644 index 000000000..92fca3384 --- /dev/null +++ b/changelog.d/pr-2497.change @@ -0,0 +1 @@ +Add error messages about refresh tokens and an invalid well-known file. \ No newline at end of file