From 60bb42ecf72bb0a842eca9fd8526ce47545a5c25 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 14 Sep 2023 14:46:55 -0400 Subject: [PATCH] Fix oauth XPC interrupt --- README.md | 2 +- Sources/Appwrite/Client.swift | 7 +++++-- Sources/Appwrite/Services/Account.swift | 11 +++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 27de181..ebf52e9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "4.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "4.0.1"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index d5f2be0..a923c30 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -23,7 +23,7 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "4.0.0", + "x-sdk-version": "4.0.1", "X-Appwrite-Response-Format": "1.4.0" ] @@ -321,18 +321,21 @@ open class Client { default: var message = "" var data = try await response.body.collect(upTo: Int.max) + var type = "" do { let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] message = dict?["message"] as? String ?? response.status.reasonPhrase + type = dict?["type"] as? String ?? "" } catch { message = data.readString(length: data.readableBytes)! } throw AppwriteError( message: message, - code: Int(response.status.code) + code: Int(response.status.code), + type: type ) } } diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 8c593c8..ea4b8b9 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -1003,7 +1003,7 @@ open class Account: Service { success: String? = nil, failure: String? = nil, scopes: [String]? = nil - ) throws -> Bool { + ) async throws -> Bool { let apiPath: String = "/account/sessions/oauth2/{provider}" .replacingOccurrences(of: "{provider}", with: provider) @@ -1017,13 +1017,12 @@ open class Account: Service { let query = "?\(client.parametersToQueryString(params: apiParams))" let url = URL(string: client.endPoint + apiPath + query)! let callbackScheme = "appwrite-callback-\(client.config["project"] ?? "")" - let group = DispatchGroup() - group.enter() - WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in - group.leave() + try await withCheckedThrowingContinuation { continuation in + WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in + continuation.resume(with: result) + } } - group.wait() return true