Skip to content

Commit

Permalink
fix(Auth): Fix multiple continuation resumes in hostedUI
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Jan 11, 2024
1 parent 003e1f3 commit 3b4da32
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
return try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<[URLQueryItem], Error>) in

// This is a workaround multiple calls to continuations in the ASWebAuthenticationSession
// which is happening due to a possible bug in the iOS platform. The idea is to null out the
// continuation once resumed.
var nullableContinuation: CheckedContinuation<[URLQueryItem], Error>? = continuation

let aswebAuthenticationSession = createAuthenticationSession(
url: url,
callbackURLScheme: callbackScheme,
Expand All @@ -42,18 +47,20 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
where: { $0.name == "error_description" }
)?.value?.trim() ?? ""
let message = "\(error) \(errorDescription)"
return continuation.resume(
nullableContinuation?.resume(
throwing: HostedUIError.serviceMessage(message))
} else {
nullableContinuation?.resume(
returning: queryItems)
}
return continuation.resume(
returning: queryItems)
} else if let error = error {
return continuation.resume(
nullableContinuation?.resume(
throwing: self.convertHostedUIError(error))
} else {
return continuation.resume(
nullableContinuation?.resume(
throwing: HostedUIError.unknown)
}
nullableContinuation = nil
})
aswebAuthenticationSession.presentationContextProvider = self
aswebAuthenticationSession.prefersEphemeralWebBrowserSession = inPrivate
Expand Down

0 comments on commit 3b4da32

Please sign in to comment.