Last active
October 14, 2020 10:09
-
-
Save aalemi97/e816c250124ebdb79fd8bf5dc1d4a9f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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