diff --git a/Tusker/Screens/Onboarding/OnboardingViewController.swift b/Tusker/Screens/Onboarding/OnboardingViewController.swift index 2ff330ca..1ee459de 100644 --- a/Tusker/Screens/Onboarding/OnboardingViewController.swift +++ b/Tusker/Screens/Onboarding/OnboardingViewController.swift @@ -93,7 +93,11 @@ class OnboardingViewController: UINavigationController { return try await withCheckedThrowingContinuation({ continuation in self.authenticationSession = ASWebAuthenticationSession(url: authorizeURL, callbackURLScheme: "tusker", completionHandler: { url, error in if let error = error { - continuation.resume(throwing: Error.authenticationSessionError(error)) + if (error as? ASWebAuthenticationSessionError)?.code == .canceledLogin { + continuation.resume(throwing: Error.cancelled) + } else { + continuation.resume(throwing: Error.authenticationSessionError(error)) + } } else if let url = url, let components = URLComponents(url: url, resolvingAgainstBaseURL: true), let item = components.queryItems?.first(where: { $0.name == "code" }), @@ -114,6 +118,7 @@ class OnboardingViewController: UINavigationController { extension OnboardingViewController { enum Error: Swift.Error { + case cancelled case registeringApp(Swift.Error) case authenticationSessionError(Swift.Error) case noAuthorizationCode @@ -122,6 +127,8 @@ extension OnboardingViewController { var localizedDescription: String { switch self { + case .cancelled: + return "Login Cancelled" case .registeringApp(let error): return "Couldn't register app: \(error)" case .authenticationSessionError(let error): @@ -142,6 +149,8 @@ extension OnboardingViewController: InstanceSelectorTableViewControllerDelegate Task { do { try await self.tryLoginTo(instanceURL: instanceURL) + } catch Error.cancelled { + // no-op, don't show an error message } catch let error as Error { let alert = UIAlertController(title: "Error Logging In", message: error.localizedDescription, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style: .default))