Skip to content

Commit

Permalink
Fix/Facebook graph response (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
yllfejziu authored May 10, 2024
1 parent 4cb21b8 commit 1f1fb65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Sources/Facebook/FacebookAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public extension FacebookAuthenticator {
let email: String?
let firstName: String?
let lastName: String?
let picture: PictureData?

struct PictureData: Decodable {
let data: PictureURL
}

struct PictureURL: Decodable {
let isSilhouette: Bool
let width: Int
let url: String
let height: Int
}
}
}

Expand Down
10 changes: 1 addition & 9 deletions Sources/Facebook/FacebookAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,11 @@ private extension FacebookAuthenticator {
request.start { _, result, error in
switch result {
case .some(let response):
guard let dict = response as? [String: String] else {
seal.reject(with: Error.invalidUserData)
return
}

let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase

do {
let data = try encoder.encode(dict)
let data = try JSONSerialization.data(withJSONObject: response, options: [])
let object = try data.decode(GraphResponse.self, with: decoder)

let authResponse = Response(
Expand Down

0 comments on commit 1f1fb65

Please sign in to comment.