add empty check for keychain credentials server (#19242)

This commit is contained in:
Parvesh Monu 2024-03-26 12:15:35 +05:30 committed by GitHub
parent 3be1532b32
commit 6a88a34d34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,23 +62,26 @@
([server username password] ([server username password]
(save-credentials server username password identity)) (save-credentials server username password identity))
([server username password callback] ([server username password callback]
(when-not (empty? server)
(-> (.setInternetCredentials ^js react-native-keychain (-> (.setInternetCredentials ^js react-native-keychain
(string/lower-case server) (string/lower-case server)
username username
password password
keychain-secure-hardware keychain-secure-hardware
keychain-restricted-availability) keychain-restricted-availability)
(.then callback)))) (.then callback)))))
(defn get-credentials (defn get-credentials
"Gets the credentials for a specified server from the Keychain" "Gets the credentials for a specified server from the Keychain"
([server] ([server]
(get-credentials server identity)) (get-credentials server identity))
([server callback] ([server callback]
(when-not (empty? server)
(-> (.getInternetCredentials ^js react-native-keychain (string/lower-case server)) (-> (.getInternetCredentials ^js react-native-keychain (string/lower-case server))
(.then callback)))) (.then callback)))))
(defn reset-credentials (defn reset-credentials
[server] [server]
(when-not (empty? server)
(-> (.resetInternetCredentials ^js react-native-keychain (string/lower-case server)) (-> (.resetInternetCredentials ^js react-native-keychain (string/lower-case server))
(.then #(when-not % (log/error (str "Error while clearing saved password.")))))) (.then #(when-not % (log/error (str "Error while clearing saved password.")))))))