mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Use AF for Piped token request
This commit is contained in:
parent
3624d186bc
commit
a04159969e
@ -1,3 +1,4 @@
|
|||||||
|
import Alamofire
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
import Foundation
|
import Foundation
|
||||||
import Siesta
|
import Siesta
|
||||||
@ -148,28 +149,43 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
login.request(
|
AF.request(
|
||||||
.post,
|
login.url,
|
||||||
json: ["username": username, "password": password]
|
method: .post,
|
||||||
)
|
parameters: ["username": username, "password": password],
|
||||||
.onSuccess { response in
|
encoding: JSONEncoding.default
|
||||||
let token = response.json.dictionaryValue["token"]?.string ?? ""
|
).responseDecodable(of: JSON.self) { [weak self] response in
|
||||||
if let error = response.json.dictionaryValue["error"]?.string {
|
guard let self else {
|
||||||
NavigationModel.shared.presentAlert(
|
return
|
||||||
title: "Account Error",
|
|
||||||
message: error
|
|
||||||
)
|
|
||||||
} else if !token.isEmpty {
|
|
||||||
AccountsModel.setToken(self.account, token)
|
|
||||||
self.objectWillChange.send()
|
|
||||||
} else {
|
|
||||||
NavigationModel.shared.presentAlert(
|
|
||||||
title: "Account Error",
|
|
||||||
message: "Could not update your token."
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.configure()
|
switch response.result {
|
||||||
|
case let .success(value):
|
||||||
|
let json = JSON(value)
|
||||||
|
let token = json.dictionaryValue["token"]?.string ?? ""
|
||||||
|
if let error = json.dictionaryValue["error"]?.string {
|
||||||
|
NavigationModel.shared.presentAlert(
|
||||||
|
title: "Account Error",
|
||||||
|
message: error
|
||||||
|
)
|
||||||
|
} else if !token.isEmpty {
|
||||||
|
AccountsModel.setToken(self.account, token)
|
||||||
|
self.objectWillChange.send()
|
||||||
|
} else {
|
||||||
|
NavigationModel.shared.presentAlert(
|
||||||
|
title: "Account Error",
|
||||||
|
message: "Could not update your token."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.configure()
|
||||||
|
|
||||||
|
case let .failure(error):
|
||||||
|
NavigationModel.shared.presentAlert(
|
||||||
|
title: "Account Error",
|
||||||
|
message: error.localizedDescription
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user