From e8f7d7b9c79d182ed1f19c8c7ed8a7b1b1965388 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 27 Mar 2023 23:01:47 +1100 Subject: [PATCH 1/3] Handle user canceled "error" in demo app --- .../ViewController+WordPressAuthenticator.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift b/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift index 5564f63d8..4e1eddbac 100644 --- a/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift +++ b/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift @@ -1,3 +1,4 @@ +import AuthenticationServices import WebKit import WordPressAuthenticator import WordPressKit @@ -96,6 +97,12 @@ extension ViewController { ) } catch let error as OAuthError { presentAlert(title: "❌", message: error.errorDescription, onDismiss: {}) + } catch let error as NSError where + error.domain == ASWebAuthenticationSessionError.errorDomain + && error.code == ASWebAuthenticationSessionError.Code.canceledLogin.rawValue { + // In a production app, the UX would be better if we didn't present an alert. + // But here, it's useful to show it to make the error handling visible for reference. + presentAlert(title: "", message: "User cancelled", onDismiss: {}) } catch { fatalError("Caught an error that was not of the expected `OAuthError` type: \(error)") } From de62e971bcc7a491b585d9e81b8bb0bd96de18dc Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 29 Mar 2023 16:56:51 +1100 Subject: [PATCH 2/3] Refine how the canceled error is caught in the demo app --- .../ViewController+WordPressAuthenticator.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift b/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift index 4e1eddbac..aa797df62 100644 --- a/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift +++ b/Demo/AuthenticatorDemo/ViewController+WordPressAuthenticator.swift @@ -97,9 +97,8 @@ extension ViewController { ) } catch let error as OAuthError { presentAlert(title: "❌", message: error.errorDescription, onDismiss: {}) - } catch let error as NSError where - error.domain == ASWebAuthenticationSessionError.errorDomain - && error.code == ASWebAuthenticationSessionError.Code.canceledLogin.rawValue { + } catch let error as ASWebAuthenticationSessionError + where error.code == ASWebAuthenticationSessionError.canceledLogin { // In a production app, the UX would be better if we didn't present an alert. // But here, it's useful to show it to make the error handling visible for reference. presentAlert(title: "", message: "User cancelled", onDismiss: {}) From 0a6af30f0bee031a939ac4a9b21ce0024a92fb73 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 29 Mar 2023 17:05:43 +1100 Subject: [PATCH 3/3] Ensure progress HUD is dismissed upon Google auth error --- .../View Related/Google/GoogleAuthViewController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPressAuthenticator/Unified Auth/View Related/Google/GoogleAuthViewController.swift b/WordPressAuthenticator/Unified Auth/View Related/Google/GoogleAuthViewController.swift index 8f821866b..05e1e2575 100644 --- a/WordPressAuthenticator/Unified Auth/View Related/Google/GoogleAuthViewController.swift +++ b/WordPressAuthenticator/Unified Auth/View Related/Google/GoogleAuthViewController.swift @@ -1,3 +1,5 @@ +import SVProgressHUD + /// View controller that handles the google authentication flow /// class GoogleAuthViewController: LoginViewController { @@ -142,6 +144,7 @@ extension GoogleAuthViewController: GoogleAuthenticatorDelegate { } func googleAuthCancelled() { + SVProgressHUD.dismiss() navigationController?.popViewController(animated: true) }