Как вызвать TouchIDAction до ввода пароля?
Есть следующий кусок кода, где для входа в учетную запись используются два метода:
- Обычный 4 значный пароль
- Аутентификация с помощью TouchID или FaceID
Вот код:
const Keyboard = ({
onPressNumericButton,
backspaceOnPress,
leftButtonLabel,
leftButtonOnClick,
isBioLoginEnabled,
touchIdAction,
code,
}: Keyboard) => (
<KeyboardContainer>
{[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
].map((r) => (
<KeyboardButtonsRowContainer>
{r.map((button) => (
<KeyboardNumericButton onPress={() => onPressNumericButton(button)} value={button} />
))}
</KeyboardButtonsRowContainer>
))}
<KeyboardButtonsRowContainer>
<KeyboardButton label={leftButtonLabel} onPress={leftButtonOnClick} />
<KeyboardNumericButton onPress={() => onPressNumericButton(0)} value={0} />
{!code && isBioLoginEnabled && touchIdAction ? (
<View style={buttonStyles.textButton}>
<TouchIdComponent action={touchIdAction} />
</View>
) : (
<BackSpaceButton onPress={backspaceOnPress} />
)}
</KeyboardButtonsRowContainer>
</KeyboardContainer>
);
Вот так выглядит компонент аутентификации с помощью TouchID:
class TouchIdComponent extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
biometryType: undefined,
};
}
async componentDidMount() {
const { biometryType } = await TouchId.getBiometryType();
biometryType && this.setState({ biometryType });
}
successHandler = () =>
loginWithToken(
this.props.action,
this.props.parameters,
this.props.parameterGroups,
this.props.formData,
this.props.updateFormData,
this.props.setExecutedAction,
this.props.startValidation,
);
failHandler = (error: any) => {
Logger.warn('failed authenticate with token', error);
Alert.alert(error.message);
};
pressHandler = () => {
TouchId.auth().then(this.successHandler).catch(this.failHandler);
};
iosButton = (source: any) => (
<TouchableOpacity onPress={this.pressHandler}>
<Image source={source} />
</TouchableOpacity>
);
androidButton = (source: any) => (
<TouchableNativeFeedback onPress={this.pressHandler}>
<Image source={source} />
</TouchableNativeFeedback>
);
render() {
const { biometryType } = this.state;
if (!biometryType) return null;
const source = biometryType === 'FaceID' ? Images.icons.faceId : Images.icons.touchId;
return Platform.OS === 'ios' ? this.iosButton(source) : this.androidButton(source);
}
}
const mapStateToProps = () =>
createStructuredSelector({
parameters: selectAllParameters,
parameterGroups: selectGroups,
formData: selectCurrentFormData,
});
const mapDispatchToProps = {
updateFormData,
startValidation,
setExecutedAction,
};
export default connect(mapStateToProps, mapDispatchToProps)(TouchIdComponent);
Вопрос: как сделать так, чтобы сначала запрашивала аутентификацию с помощью TouchID и FaceID (При наличии таковых), только потом через 4 значный код?