working jwt
This commit is contained in:
parent
dc6b03dd3c
commit
4f2e0f245c
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import SwiftyJSON
|
import SwiftyJSON
|
||||||
import KeychainAccess
|
|
||||||
|
|
||||||
@UIApplicationMain
|
@UIApplicationMain
|
||||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
@ -45,26 +45,39 @@ class LiveUser: ObservableObject {
|
|||||||
let api = PlaylistApi.getPlaylists
|
let api = PlaylistApi.getPlaylists
|
||||||
RequestBuilder.buildRequest(apiRequest: api).responseJSON{ response in
|
RequestBuilder.buildRequest(apiRequest: api).responseJSON{ response in
|
||||||
|
|
||||||
guard let data = response.data else {
|
switch response.result {
|
||||||
fatalError("error getting playlists")
|
case .success:
|
||||||
}
|
|
||||||
|
|
||||||
guard let json = try? JSON(data: data) else {
|
guard let data = response.data else {
|
||||||
fatalError("error parsing reponse")
|
fatalError("error getting playlists")
|
||||||
}
|
}
|
||||||
|
|
||||||
let playlists = json["playlists"].arrayValue
|
guard let json = try? JSON(data: data) else {
|
||||||
|
fatalError("error parsing reponse")
|
||||||
|
}
|
||||||
|
|
||||||
// update state
|
let playlists = json["playlists"].arrayValue
|
||||||
self.playlists = PlaylistApi.fromJSON(playlist: playlists).sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
|
|
||||||
|
|
||||||
self.isRefreshingPlaylists = false
|
// update state
|
||||||
|
self.playlists = PlaylistApi.fromJSON(playlist: playlists).sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
|
||||||
|
|
||||||
let encoder = JSONEncoder()
|
self.isRefreshingPlaylists = false
|
||||||
do {
|
|
||||||
UserDefaults.standard.set(String(data: try encoder.encode(playlists), encoding: .utf8), forKey: "playlists")
|
let encoder = JSONEncoder()
|
||||||
} catch {
|
do {
|
||||||
print("error encoding playlists: \(error)")
|
UserDefaults.standard.set(String(data: try encoder.encode(playlists), encoding: .utf8), forKey: "playlists")
|
||||||
|
} catch {
|
||||||
|
print("error encoding playlists: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
case .failure:
|
||||||
|
|
||||||
|
switch response.response?.statusCode {
|
||||||
|
case 401:
|
||||||
|
self.loggedIn = false
|
||||||
|
case _:
|
||||||
|
print("error")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,8 @@ public enum AuthMethod {
|
|||||||
struct RequestBuilder {
|
struct RequestBuilder {
|
||||||
static func buildRequest(apiRequest: ApiRequest) -> Alamofire.DataRequest {
|
static func buildRequest(apiRequest: ApiRequest) -> Alamofire.DataRequest {
|
||||||
|
|
||||||
print(apiRequest.authMethod)
|
|
||||||
print(apiRequest.headers)
|
|
||||||
print(apiRequest.httpMethod)
|
|
||||||
|
|
||||||
let txHeaders = apiRequest.authMethod?.auth(headers: apiRequest.headers)
|
let txHeaders = apiRequest.authMethod?.auth(headers: apiRequest.headers)
|
||||||
|
|
||||||
print(txHeaders)
|
|
||||||
print(apiRequest.parameters)
|
|
||||||
print(apiRequest.domain + apiRequest.path)
|
|
||||||
|
|
||||||
if apiRequest.parameters != nil {
|
if apiRequest.parameters != nil {
|
||||||
if apiRequest.parameterType != nil {
|
if apiRequest.parameterType != nil {
|
||||||
|
|
||||||
|
@ -39,10 +39,7 @@ struct LoginScreen: View {
|
|||||||
let keychain = Keychain(service: "xyz.sarsoo.music.login")
|
let keychain = Keychain(service: "xyz.sarsoo.music.login")
|
||||||
|
|
||||||
keychain["username"] = username
|
keychain["username"] = username
|
||||||
keychain["password"] = password
|
// keychain["password"] = password
|
||||||
|
|
||||||
print(username)
|
|
||||||
print(password)
|
|
||||||
|
|
||||||
let api = AuthApi.token(username: username, password: password)
|
let api = AuthApi.token(username: username, password: password)
|
||||||
RequestBuilder.buildRequest(apiRequest: api)
|
RequestBuilder.buildRequest(apiRequest: api)
|
||||||
|
@ -29,6 +29,7 @@ struct SettingsList: View {
|
|||||||
do {
|
do {
|
||||||
try keychain.remove("username")
|
try keychain.remove("username")
|
||||||
try keychain.remove("password")
|
try keychain.remove("password")
|
||||||
|
try keychain.remove("jwt")
|
||||||
|
|
||||||
self.liveUser.loggedIn = false
|
self.liveUser.loggedIn = false
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user