Last active
December 7, 2017 16:19
-
-
Save nderkach/b7b2ef3dd6ff8e87ab44c1d6dbce7fbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@discardableResult func login(_ email: String, _ password: String, onSuccess: @escaping () -> Void, onFailure: @escaping (String) -> Void) -> Request { | |
let request = service.resource("/login") | |
.request(.post, json: ["email": email, "password": password]) | |
.onSuccess { entity in | |
guard let json: [String: String] = entity.typedContent() else { | |
onFailure("JSON parsing error") | |
return | |
} | |
guard let token = json["jwt"] else { | |
onFailure("JWT token missing") | |
return | |
} | |
self.authToken = token | |
onSuccess() | |
} | |
.onFailure { (error) in | |
onFailure(error.userMessage) | |
} | |
return request | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment