Add username/password login and keychain manager

Fix #224
This commit is contained in:
Arkadiusz Fal
2022-08-26 01:36:46 +02:00
parent 08ed810b9e
commit 2f2fd67860
19 changed files with 280 additions and 107 deletions

26
Model/KeychainModel.swift Normal file
View 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"))
}
}