循环世博生物识别认证直到成功

Tot*_*ndo 5 biometrics fingerprint react-native expo

我正在尝试使用 React-native 和 Expo 在 Android 上实现生物识别身份验证(faceID/指纹)。

使用该LocalAuthentication.authenticateAsync()功能,用户能够使用他的生物特征进行身份验证。但如果失败,用户必须再次按下生物识别认证。

所以我尝试了一个 recursif 或 do while 循环的小技巧,但结果很奇怪:

const scanFingerPrint = async () => {
        try {
            const results = await DeviceService.biometricAuthentication();
            if (results.success) {
                SecureStoreService.getCredential()
                    .then(credentials => onScan(credentials));
            } else {
                ShakeAnimation(animatedValueModal);
                return scanFingerPrint();
            }
        } catch (e) {
            console.log(e);
        }
    };
Run Code Online (Sandbox Code Playgroud)

使用此代码,如果用户未通过生物识别身份验证,它将无限地传入“else”...

所以我想知道如何在android上处理它。

Tot*_*ndo 0

Expo 在本地身份验证的结果上提供“错误”键。为了不处理硬件错误,我使用了这个:

if (!results.success) {
                switch (results.error) {
                    case "lockout":
                        setLocked(true);
                        break;
                    case "authentication_failed" || "too_fast":
                        ShakeAnimation(animatedValueModal);
                        await scanBiometric();
                        break;
                    case "user_cancel" :
                        break;
                    default:
                        ShakeAnimation(animatedValueModal);
                        break;
                }
            }
Run Code Online (Sandbox Code Playgroud)