commit f522fc79df2b1b39145826b34415854f8e2557eb
parent fead2a498ff82e675e55788b3deb502efe0baf3f
Author: William Casarin <jb55@jb55.com>
Date: Thu, 28 Jul 2022 12:52:58 -0700
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>
Diffstat:
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/damus/Util/Keys.swift b/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()
diff --git a/damus/Views/LoginView.swift b/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)
diff --git a/damus/damusApp.swift b/damus/damusApp.swift
@@ -36,6 +36,7 @@ struct MainView: View {
}
}
.onReceive(handle_notify(.logout)) { _ in
+ clear_keypair()
keypair = nil
}
.onAppear {