Skip to content

Commit

Permalink
fix(Auth): Fix multiple continuation resumes in hostedUI (#3466)
Browse files Browse the repository at this point in the history
* fix(Auth): Fix multiple continuation resumes in hostedUI

* use weak self.

* updated with review comments

* adding back return statements.

* worked on review comment

* fixing availability on iOS
  • Loading branch information
harsh62 authored Jan 15, 2024
1 parent 3b97722 commit a961c64
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
#if os(iOS) || os(macOS)
self.webPresentation = presentationAnchor

return try await withCheckedThrowingContinuation {
return try await withCheckedThrowingContinuation { [weak self]
(continuation: CheckedContinuation<[URLQueryItem], Error>) in
guard let self else { return }

let aswebAuthenticationSession = createAuthenticationSession(
url: url,
callbackURLScheme: callbackScheme,
completionHandler: { url, error in

completionHandler: { [weak self] url, error in
guard let self else { return }
if let url = url {
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
let queryItems = urlComponents?.queryItems ?? []
Expand All @@ -44,9 +45,10 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
let message = "\(error) \(errorDescription)"
return continuation.resume(
throwing: HostedUIError.serviceMessage(message))
} else {
return continuation.resume(
returning: queryItems)
}
return continuation.resume(
returning: queryItems)
} else if let error = error {
return continuation.resume(
throwing: self.convertHostedUIError(error))
Expand All @@ -59,7 +61,13 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
aswebAuthenticationSession.prefersEphemeralWebBrowserSession = inPrivate

DispatchQueue.main.async {
aswebAuthenticationSession.start()
var canStart = true
if #available(macOS 10.15.4, iOS 13.4, *) {
canStart = aswebAuthenticationSession.canStart
}
if canStart {
aswebAuthenticationSession.start()
}
}
}

Expand Down

0 comments on commit a961c64

Please sign in to comment.