Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Biometrics button on login screen #18106

Merged
merged 14 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/status_im2/common/biometric/constants.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns status-im2.common.biometric.constants)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have status-im2.constants for all constants


(def ^:const auth-error-user-canceled "USER_CANCELED")
(def ^:const auth-error-user-fallback "USER_USER_FALLBACK")
(def ^:const auth-error-not-available "NOT_AVAILABLE")
(def ^:const auth-error-not-enrolled "NOT_ENROLLED")
9 changes: 7 additions & 2 deletions src/status_im2/common/biometric/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[react-native.async-storage :as async-storage]
[react-native.platform :as platform]
[react-native.touch-id :as touch-id]
[status-im2.common.biometric.constants :as biometric-constants]
[status-im2.common.keychain.events :as keychain]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
Expand Down Expand Up @@ -46,8 +47,12 @@
{:events [:biometric/show-message]}
[_ code]
(let [handle-error? (and code
(not (contains? #{"USER_CANCELED" "USER_FALLBACK"} code)))
content (if (#{"NOT_AVAILABLE" "NOT_ENROLLED"} code)
(not (contains? #{biometric-constants/auth-error-user-canceled
biometric-constants/auth-error-user-fallback}
code)))
content (if (#{biometric-constants/auth-error-not-available
biometric-constants/auth-error-not-enrolled}
code)
(i18n/label :t/grant-face-id-permissions)
(i18n/label :t/biometric-auth-error {:code code}))]
(when handle-error?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
{:container-style style/auth-button
:on-press on-press-biometrics
:icon-only? true
:background :blur
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be passed as a prop and defaulted to false. wdyt? I think in some flows this could be incorrect 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text input has :blur? enabled as well. Do we have cases where the input is used without the blur?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:type :outline}
:i/face-id])]
(when error?
Expand Down
4 changes: 2 additions & 2 deletions src/status_im2/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[status-im.mobile-sync-settings.core :as mobile-network]
[status-im.pairing.core :as pairing]
[status-im.stickers.core :as stickers]
[status-im2.common.biometric.constants :as biometric-constants]
[status-im2.common.keychain.events :as keychain]
[status-im2.common.log :as logging]
[status-im2.common.universal-links :as universal-links]
Expand Down Expand Up @@ -218,8 +219,7 @@
(fn [{:keys [db]} [code]]
(let [key-uid (get-in db [:profile/login :key-uid])]
{:db db
:fx [[:dispatch [:init-root :profiles]]
(if (= code "NOT_ENROLLED")
:fx [(if (= code biometric-constants/auth-error-not-enrolled)
[:biometric/supress-not-enrolled-error
[key-uid
[:biometric/show-message code]]]
Expand Down
12 changes: 10 additions & 2 deletions src/status_im2/contexts/profile/profiles/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
:on-card-press (fn []
(rf/dispatch
[:profile/profile-selected key-uid])
(rf/dispatch
[:profile.login/login-with-biometric-if-available key-uid])
(when-not keycard-pairing (set-hide-profiles)))}]))

(defn- f-profiles-section
Expand Down Expand Up @@ -206,8 +208,14 @@
:profile-picture profile-picture
:card-style style/login-profile-card}]
[standard-authentication/password-input
{:shell? true
:default-password password}]]
{:shell? true
:on-press-biometrics (fn []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? Have you handled the case where biometrics fails -> password input shows, then you press biometric authenticate again and let it fail -> password input shows then you press biometric authenticate again ... (to infinity :) )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the flow 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong let me test out your branch 😀

(rf/dispatch [:biometric/authenticate
{:on-success #(rf/dispatch
[:profile.login/biometric-success])
:on-fail #(rf/dispatch
[:profile.login/biometric-auth-fail %])}]))
:default-password password}]]
[quo/button
{:size 40
:type :primary
Expand Down