2022-08-25 23:36:46 +00:00
|
|
|
import Foundation
|
|
|
|
import KeychainAccess
|
|
|
|
|
|
|
|
struct KeychainModel {
|
2023-04-22 13:08:33 +00:00
|
|
|
static var shared = Self()
|
2022-08-25 23:36:46 +00:00
|
|
|
|
|
|
|
var keychain = Keychain(service: "stream.yattee.app")
|
|
|
|
|
|
|
|
func updateAccountKey(_ account: Account, _ key: String, _ value: String) {
|
2023-04-22 15:14:15 +00:00
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
keychain[accountKey(account, key)] = value
|
|
|
|
}
|
2022-08-25 23:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getAccountKey(_ account: Account, _ key: String) -> String? {
|
|
|
|
keychain[accountKey(account, key)]
|
|
|
|
}
|
|
|
|
|
|
|
|
func accountKey(_ account: Account, _ key: String) -> String {
|
|
|
|
"\(account.id)-\(key)"
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeAccountKeys(_ account: Account) {
|
2023-04-22 15:14:15 +00:00
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
try? keychain.remove(accountKey(account, "token"))
|
|
|
|
try? keychain.remove(accountKey(account, "username"))
|
|
|
|
try? keychain.remove(accountKey(account, "password"))
|
|
|
|
}
|
2022-08-25 23:36:46 +00:00
|
|
|
}
|
|
|
|
}
|