Skip to content

Commit a961c64

Browse files
authored
fix(Auth): Fix multiple continuation resumes in hostedUI (#3466)
* 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
1 parent 3b97722 commit a961c64

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
2424
#if os(iOS) || os(macOS)
2525
self.webPresentation = presentationAnchor
2626

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

3031
let aswebAuthenticationSession = createAuthenticationSession(
3132
url: url,
3233
callbackURLScheme: callbackScheme,
33-
completionHandler: { url, error in
34-
34+
completionHandler: { [weak self] url, error in
35+
guard let self else { return }
3536
if let url = url {
3637
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
3738
let queryItems = urlComponents?.queryItems ?? []
@@ -44,9 +45,10 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
4445
let message = "\(error) \(errorDescription)"
4546
return continuation.resume(
4647
throwing: HostedUIError.serviceMessage(message))
48+
} else {
49+
return continuation.resume(
50+
returning: queryItems)
4751
}
48-
return continuation.resume(
49-
returning: queryItems)
5052
} else if let error = error {
5153
return continuation.resume(
5254
throwing: self.convertHostedUIError(error))
@@ -59,7 +61,13 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
5961
aswebAuthenticationSession.prefersEphemeralWebBrowserSession = inPrivate
6062

6163
DispatchQueue.main.async {
62-
aswebAuthenticationSession.start()
64+
var canStart = true
65+
if #available(macOS 10.15.4, iOS 13.4, *) {
66+
canStart = aswebAuthenticationSession.canStart
67+
}
68+
if canStart {
69+
aswebAuthenticationSession.start()
70+
}
6371
}
6472
}
6573

0 commit comments

Comments
 (0)