Skip to content

Instantly share code, notes, and snippets.

@aalemi97
Last active October 14, 2020 10:09
Show Gist options
  • Save aalemi97/e816c250124ebdb79fd8bf5dc1d4a9f4 to your computer and use it in GitHub Desktop.
Save aalemi97/e816c250124ebdb79fd8bf5dc1d4a9f4 to your computer and use it in GitHub Desktop.
func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) {
var request = urlRequest
guard let token = UserDefaultsManager.shared.getToken() else {
completion(.success(urlRequest))
return
}
let bearerToken = "Bearer \(token)"
request.setValue(bearerToken, forHTTPHeaderField: "Authorization")
print("\nadapted; token added to the header field is: \(bearerToken)\n")
completion(.success(request))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment