Skip to content

Commit

Permalink
Properly handle cancellations
Browse files Browse the repository at this point in the history
  • Loading branch information
tagavari committed Oct 18, 2022
1 parent 171192b commit e8e1845
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions AirMessage/Controllers/AccountConnectViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,26 @@ class AccountConnectViewController: NSViewController {
)

redirectHandler.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: view.window!) { [weak self] result, error in
guard let self = self else { return }

//Surface errors to the user
if let error = error {
self.showError(message: error.localizedDescription, showReconnect: false)
return
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

//Surface errors to the user
if let error = error as? NSError {
//Don't show cancellation errors
if error.domain == OIDGeneralErrorDomain
&& (error.code == OIDErrorCode.userCanceledAuthorizationFlow.rawValue
|| error.code == OIDErrorCode.programCanceledAuthorizationFlow.rawValue) {
self.dismiss(self)
} else {
self.showError(message: error.localizedDescription, showReconnect: false)
}
return
}

//Start a connection with the ID token
let idToken = result!.lastTokenResponse!.idToken!
self.startConnection(idToken: idToken, callbackURL: redirectURL.absoluteString)
}

//Start a connection with the ID token
let idToken = result!.lastTokenResponse!.idToken!
self.startConnection(idToken: idToken, callbackURL: redirectURL.absoluteString)
}

//Update the view
Expand Down Expand Up @@ -102,7 +111,7 @@ class AccountConnectViewController: NSViewController {

//Exchange the refresh token
exchangeFirebaseIDPToken(idToken, providerID: "google.com", callbackURL: callbackURL) { [weak self] result, error in
DispatchQueue.main.async {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

//Check for errors
Expand Down

0 comments on commit e8e1845

Please sign in to comment.