From 6842e044b748a03256ae7d2cf98c5c1cd67a81d3 Mon Sep 17 00:00:00 2001 From: Jamil Date: Mon, 3 Feb 2025 05:47:33 +0000 Subject: [PATCH] fix(apple): Don't try to sign in if user cancels (#7996) This fixes a minor regression introduced in f779fe9667 where we would incorrectly show an error dialog if the user cancels sign in because the `authResponse` is invalid. --- .../Sources/FirezoneKit/Models/WebAuthSession.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Models/WebAuthSession.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Models/WebAuthSession.swift index 9a270c545..818ad6fcc 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Models/WebAuthSession.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Models/WebAuthSession.swift @@ -22,12 +22,14 @@ struct WebAuthSession { let anchor = PresentationAnchor() - let authResponse = try await withCheckedThrowingContinuation { continuation in + let authResponse: AuthResponse? = try await withCheckedThrowingContinuation { continuation in let session = ASWebAuthenticationSession(url: url, callbackURLScheme: scheme) { returnedURL, error in do { if let error = error as? ASWebAuthenticationSessionError, error.code == .canceledLogin { // User canceled sign in + continuation.resume(returning: nil) + return } else if let error = error { throw error } @@ -50,7 +52,9 @@ struct WebAuthSession { session.start() } - try await store.signIn(authResponse: authResponse) + if let authResponse { + try await store.signIn(authResponse: authResponse) + } } }