mirror of
https://github.com/yattee/yattee.git
synced 2025-10-12 18:38:16 +00:00
26
Model/KeychainModel.swift
Normal file
26
Model/KeychainModel.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
import KeychainAccess
|
||||
|
||||
struct KeychainModel {
|
||||
static var shared = KeychainModel()
|
||||
|
||||
var keychain = Keychain(service: "stream.yattee.app")
|
||||
|
||||
func updateAccountKey(_ account: Account, _ key: String, _ value: String) {
|
||||
keychain[accountKey(account, key)] = value
|
||||
}
|
||||
|
||||
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) {
|
||||
try? keychain.remove(accountKey(account, "token"))
|
||||
try? keychain.remove(accountKey(account, "username"))
|
||||
try? keychain.remove(accountKey(account, "password"))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user