Save biometrics

This commit is contained in:
Andrea Maria Piana 2023-03-27 12:49:35 +01:00
parent 9c0ab739ea
commit a10425e318
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
4 changed files with 74 additions and 25 deletions

View File

@ -125,6 +125,28 @@
(fn [[cb options]]
(authenticate-fx #(cb %) options)))
(re-frame/reg-fx
:biometric/enable-and-save-password
(fn [{:keys [key-uid
masked-password
on-success
on-error]}]
(-> (keychain/save-user-password!
key-uid
masked-password)
(.then
(fn [_]
(keychain/save-auth-method!
key-uid
keychain/auth-method-biometric)))
(.then
(fn [_]
(when on-success
(on-success))))
(.catch (fn [error]
(when on-error
(on-error error)))))))
(rf/defn update-biometric
[{db :db :as cofx} biometric-auth?]
(let [key-uid (or (get-in db [:multiaccount :key-uid])

View File

@ -480,7 +480,7 @@
(re-frame/dispatch [:syncing/pairing-completed])
(get db :onboarding-2/new-account?)
(re-frame/dispatch [:navigate-to :enable-notifications])
(re-frame/dispatch [:onboarding-2/finalize-setup])
(get db :tos/accepted?)
(re-frame/dispatch [:init-root :shell-stack])

View File

@ -155,19 +155,36 @@
(callback nil))))
(callback nil))))))
(defn save-user-password!
[key-uid password]
(save-credentials
key-uid
key-uid
(security/safe-unmask-data password)
#(when-not %
(log/error
(str "Error while saving password."
" "
"The app will continue to work normally, "
"but you will have to login again next time you launch it.")))))
(defn save-auth-method!
[key-uid method]
(save-credentials
(str key-uid "-auth")
key-uid
method
#(when-not %
(log/error
(str "Error while saving auth method."
" "
"The app will continue to work normally, "
"but you will have to login again next time you launch it.")))))
(re-frame/reg-fx
:keychain/save-user-password
(fn [[key-uid password]]
(save-credentials
key-uid
key-uid
(security/safe-unmask-data password)
#(when-not %
(log/error
(str "Error while saving password."
" "
"The app will continue to work normally, "
"but you will have to login again next time you launch it."))))))
(fn [[key-uid masked-password]]
(save-user-password! key-uid masked-password)))
(re-frame/reg-fx
:keychain/save-auth-method
@ -178,16 +195,7 @@
"method"
method)
(when-not (empty? key-uid) ; key-uid may be nil after restore from local pairing
(save-credentials
(str key-uid "-auth")
key-uid
method
#(when-not %
(log/error
(str "Error while saving auth method."
" "
"The app will continue to work normally, "
"but you will have to login again next time you launch it.")))))))
(save-auth-method! key-uid method))))
(re-frame/reg-fx
:keychain/save-keycard-keys

View File

@ -1,6 +1,7 @@
(ns status-im2.contexts.onboarding.events
(:require
[utils.re-frame :as rf]
[taoensso.timbre :as log]
[re-frame.core :as re-frame]
[status-im.utils.types :as types]
[status-im2.config :as config]
@ -101,9 +102,7 @@
:previewPrivacy config/blank-preview?}]
{effect request
:dispatch [:navigate-to :generating-keys]
:db (-> db
(dissoc :onboarding-2/profile)
(assoc :onboarding-2/new-account? true))}))
:db (assoc db :onboarding-2/new-account? true)}))
(rf/defn on-delete-profile-success
{:events [:onboarding-2/on-delete-profile-success]}
@ -151,3 +150,23 @@
;; Restart the flow
{:db (dissoc db :onboarding-2/profile)
:dispatch [:navigate-to :create-profile]})
(rf/defn onboarding-new-account-finalize-setup
{:events [:onboarding-2/finalize-setup]}
[{:keys [db]}]
(let [masked-password (get-in db [:onboarding-2/profile :password])
key-uid (get-in db [:multiaccount :key-uid])
biometric-enabled? (=
constants/auth-method-biometric
(get-in db [:onboarding-2/profile :auth-method]))]
(cond-> {:db (dissoc db :onboarding-2/profile)
:dispatch [:navigate-to :enable-notifications]}
biometric-enabled?
(assoc :biometric/enable-and-save-password
{:key-uid key-uid
:masked-password masked-password
:on-success #(log/debug "successfully saved biometric")
:on-error #(log/error "failed to save biometrics"
{:key-uid key-uid
:error %})}))))