Skip to content

Commit

Permalink
Merge pull request #43 from appwrite/dev
Browse files Browse the repository at this point in the history
Fix oauth XPC interrupt
  • Loading branch information
abnegate authored Sep 14, 2023
2 parents 4478da2 + 60bb42e commit c53379f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "4.0.0"),
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "4.0.1"),
],
```

Expand Down
7 changes: 5 additions & 2 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

Expand Down Expand Up @@ -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
)
}
}
Expand Down
11 changes: 5 additions & 6 deletions Sources/Appwrite/Services/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down

0 comments on commit c53379f

Please sign in to comment.