From 159dbfe8d49cb27d8cf0ecd7dcfc79c073bde617 Mon Sep 17 00:00:00 2001 From: Nichole Martinez <101313323+nicholemnl@users.noreply.github.com> Date: Mon, 21 Mar 2022 13:19:12 +0800 Subject: [PATCH] Fix auth with Biometrics logic and validations --- machines/auth.ts | 5 +- machines/biometrics.ts | 10 ++-- screens/AuthScreen.tsx | 16 +++++- screens/AuthScreenController.ts | 78 ++++++++++++++++++++-------- screens/BiometricScreen.tsx | 68 ++++-------------------- screens/BiometricScreenController.ts | 48 +++++++++-------- screens/WelcomeScreenController.ts | 5 +- 7 files changed, 117 insertions(+), 113 deletions(-) diff --git a/machines/auth.ts b/machines/auth.ts index 20e2a381..17b1631f 100644 --- a/machines/auth.ts +++ b/machines/auth.ts @@ -55,6 +55,7 @@ export const authMachine = model.createMachine( checkingAuth: { always: [ { cond: 'hasPasscodeSet', target: 'unauthorized' }, + { cond: 'hasBiometricSet', target: 'unauthorized' }, { target: 'settingUp' }, ], }, @@ -64,7 +65,6 @@ export const authMachine = model.createMachine( target: 'authorized', actions: ['setPasscode', 'storeContext'], }, - // TODO: biometrics login SETUP_BIOMETRICS: { target: 'authorized', actions: ['setBiometrics', 'storeContext'], @@ -109,7 +109,7 @@ export const authMachine = model.createMachine( }), setBiometrics: model.assign({ - biometrics: '', // TODO + biometrics: () => 'true', }), }, @@ -117,6 +117,7 @@ export const authMachine = model.createMachine( hasData: (_, event: StoreResponseEvent) => event.response != null, hasPasscodeSet: (context) => context.passcode !== '', + hasBiometricSet: (context) => context.biometrics !== '' }, } ); diff --git a/machines/biometrics.ts b/machines/biometrics.ts index b2cb648d..65fa5b6f 100644 --- a/machines/biometrics.ts +++ b/machines/biometrics.ts @@ -1,6 +1,6 @@ import { createModel } from "xstate/lib/model"; import * as LocalAuthentication from 'expo-local-authentication'; -import { assign, send, StateFrom } from "xstate"; +import { assign, StateFrom } from "xstate"; // --- CREATE MODEL ----------------------------------------------------------- @@ -90,9 +90,11 @@ export const biometricsMachine = model.createMachine( authenticating: { invoke: { src: () => async () => { - console.log('authenticating invoked'); - let res = await LocalAuthentication.authenticateAsync() - console.log("authenticating result", res) + console.log('[BIOMETRIC_MACHINE] authenticating invoked'); + let res = await LocalAuthentication.authenticateAsync({ + promptMessage: 'Biometric Authentication', + }) + console.log("[BIOMETRIC_MACHINE] authenticating result", res) return res.success; }, onError: 'failure', diff --git a/screens/AuthScreen.tsx b/screens/AuthScreen.tsx index 7ffc6563..51ad24f5 100644 --- a/screens/AuthScreen.tsx +++ b/screens/AuthScreen.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { Icon } from 'react-native-elements'; +import { MessageOverlay } from '../components/MessageOverlay'; import { Button, Centered, Column, Text } from '../components/ui'; import { Colors } from '../components/ui/styleUtils'; import { RootRouteProps } from '../routes'; @@ -7,9 +8,15 @@ import { useAuthScreen } from './AuthScreenController'; export const AuthScreen: React.FC = (props) => { const controller = useAuthScreen(props); - console.log('-------->CONTROLLER', controller) + // console.log('-------->CONTROLLER', controller) + return ( + Would you like to use biometrics{'\n'}to unlock the application? @@ -19,7 +26,12 @@ export const AuthScreen: React.FC = (props) => { -