Browse Source

logout: clear keypair on logout

Fixes: #12
Reported-by: Jeff Thibault (github:jeffthibault)
Changelog-Fixed: Logging out now resets your keypair and actually logs out
Signed-off-by: William Casarin <jb55@jb55.com>
profiles-everywhere
William Casarin 2 years ago
parent
commit
f522fc79df
  1. 11
      damus/Util/Keys.swift
  2. 4
      damus/Views/LoginView.swift
  3. 1
      damus/damusApp.swift

11
damus/Util/Keys.swift

@ -84,15 +84,24 @@ func save_privkey(privkey: String) {
UserDefaults.standard.set(privkey, forKey: "privkey")
}
func clear_privkey() {
func clear_saved_privkey() {
UserDefaults.standard.removeObject(forKey: "privkey")
}
func clear_saved_pubkey() {
UserDefaults.standard.removeObject(forKey: "pubkey")
}
func save_keypair(pubkey: String, privkey: String) {
save_pubkey(pubkey: pubkey)
save_privkey(privkey: privkey)
}
func clear_keypair() {
clear_saved_privkey()
clear_saved_pubkey()
}
func get_saved_keypair() -> Keypair? {
get_saved_pubkey().flatMap { pubkey in
let privkey = get_saved_privkey()

4
damus/Views/LoginView.swift

@ -139,12 +139,12 @@ func process_login(_ key: ParsedKey, is_pubkey: Bool) -> Bool {
save_pubkey(pubkey: pk)
case .pub(let pub):
clear_privkey()
clear_saved_privkey()
save_pubkey(pubkey: pub)
case .hex(let hexstr):
if is_pubkey {
clear_privkey()
clear_saved_privkey()
save_pubkey(pubkey: hexstr)
} else {
save_privkey(privkey: hexstr)

1
damus/damusApp.swift

@ -36,6 +36,7 @@ struct MainView: View {
}
}
.onReceive(handle_notify(.logout)) { _ in
clear_keypair()
keypair = nil
}
.onAppear {

Loading…
Cancel
Save