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

Handle user canceled "error" in demo app #762

Merged
merged 3 commits into from
Mar 29, 2023
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
@@ -1,3 +1,4 @@
import AuthenticationServices
import WebKit
import WordPressAuthenticator
import WordPressKit
Expand Down Expand Up @@ -96,6 +97,11 @@ extension ViewController {
)
} catch let error as OAuthError {
presentAlert(title: "❌", message: error.errorDescription, onDismiss: {})
} 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: {})
} catch {
fatalError("Caught an error that was not of the expected `OAuthError` type: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import SVProgressHUD

/// View controller that handles the google authentication flow
///
class GoogleAuthViewController: LoginViewController {
Expand Down Expand Up @@ -142,6 +144,7 @@ extension GoogleAuthViewController: GoogleAuthenticatorDelegate {
}

func googleAuthCancelled() {
SVProgressHUD.dismiss()
navigationController?.popViewController(animated: true)
}

Expand Down