mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:04:42 +00:00
29 lines
575 B
Swift
29 lines
575 B
Swift
import Combine
|
|
import Foundation
|
|
|
|
class AuthContext: ObservableObject {
|
|
static let shared = AuthContext()
|
|
@Published var needsPassword = false
|
|
private(set) var password: String?
|
|
|
|
init() {
|
|
// Auto-login from Keychain
|
|
if let saved = KeychainHelper.shared.load() {
|
|
self.password = saved
|
|
}
|
|
}
|
|
|
|
func setPassword(_ pass: String) {
|
|
self.password = pass
|
|
self.needsPassword = false
|
|
// Persist
|
|
KeychainHelper.shared.save(pass)
|
|
}
|
|
|
|
func clear() {
|
|
self.password = nil
|
|
// Remove persistence
|
|
KeychainHelper.shared.delete()
|
|
}
|
|
}
|