Skip to content

Instantly share code, notes, and snippets.

@nderkach
Last active December 7, 2017 16:19
Show Gist options
  • Save nderkach/b7b2ef3dd6ff8e87ab44c1d6dbce7fbb to your computer and use it in GitHub Desktop.
Save nderkach/b7b2ef3dd6ff8e87ab44c1d6dbce7fbb to your computer and use it in GitHub Desktop.
@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