fix(#384 #394): biometrics toggle not working

This commit is contained in:
Paolo Miguel de Leon
2023-01-13 13:56:48 +08:00
parent 87040497c9
commit a7d16322b6

View File

@@ -1,6 +1,7 @@
import { createModel } from 'xstate/lib/model';
import * as LocalAuthentication from 'expo-local-authentication';
import { EventFrom, MetaObject, StateFrom } from 'xstate';
import { Platform } from 'react-native';
// ----- CREATE MODEL ---------------------------------------------------------
const model = createModel(
@@ -97,6 +98,9 @@ export const biometricsMachine = model.createMachine(
authenticating: {
invoke: {
src: () => async () => {
if (Platform.OS === 'android') {
await LocalAuthentication.cancelAuthenticate();
}
const res = await LocalAuthentication.authenticateAsync({
promptMessage: 'Biometric Authentication',
@@ -112,6 +116,9 @@ export const biometricsMachine = model.createMachine(
actions: ['setStatus'],
},
},
on: {
AUTHENTICATE: 'authenticating',
},
},
reauthenticating: {
@@ -145,6 +152,7 @@ export const biometricsMachine = model.createMachine(
SET_IS_AVAILABLE: {
target: '#biometrics.available',
},
AUTHENTICATE: 'authenticating',
},
},
@@ -186,6 +194,9 @@ export const biometricsMachine = model.createMachine(
},
},
},
on: {
AUTHENTICATE: 'authenticating',
},
},
},
},