Skip to content

Instantly share code, notes, and snippets.

@thiagobutignon
Last active September 17, 2020 20:47
Show Gist options
  • Save thiagobutignon/9a005857e54de54d71883fa7bbb16e4b to your computer and use it in GitHub Desktop.
Save thiagobutignon/9a005857e54de54d71883fa7bbb16e4b to your computer and use it in GitHub Desktop.
AuthorizationDecorator
class AuthorizationDecorator: HttpClient {
private let httpClient: HttpClient
public init(httpClient: HttpClient) {
self.httpClient = httpClient
}
public func request(data: HttpRequest, completion: @escaping (Result<Data?, HttpError>) -> Void) {
let getToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjAwMzczNTczLCJleHAiOjE2MDA0NTk5NzN9.kKCRLckJdCaSMks6WBDX52wIAB92E8wTnHgPix3PxW4"
data.headers!["Authorization"] = "Bearer \(getToken)"
// Erro: Cannot assign through subscript: 'data' is a 'let' constant
httpClient.request(data: data, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment