neckaros / secure_application

Secure your application from prying eyes
MIT License
102 stars 57 forks source link

onNeedUnlock is called over and over again #51

Open blueberry6401 opened 2 months ago

blueberry6401 commented 2 months ago

There's an issue making onNeedUnlock is called over and over again.

Reproduce:

  1. Run the example
  2. Install local_auth
  3. Modify onNeedUnlock as below

    onNeedUnlock: (secure) async {
          print(
              'need unlock maybe use biometric to confirm and then sercure.unlock() or you can use the lockedBuilder');
          try {
            final LocalAuthentication auth = LocalAuthentication();
    
            var authResult = await auth.authenticate(
              localizedReason: 'ZZZ',
              options: AuthenticationOptions(
                biometricOnly: false,
              ),
            );
            if (authResult) {
              secure?.unlock();
              return SecureApplicationAuthenticationStatus.SUCCESS;
            }
            else {
              return SecureApplicationAuthenticationStatus.FAILED;
            }
          } catch (e) {
            return SecureApplicationAuthenticationStatus.FAILED;
          }
          return null;
        },
  4. If the app asks for FaceID => face not matched => Cancel => onNeedUnlock is called over and over.

This is because of appstate changed to resumed when face id is dismissed. I don't know this is a bug or not, but I think onNeedUnlock should not work like that. Currently I put a small delay after .authenticate() to workaround this.

Screen recording: https://github.com/neckaros/secure_application/assets/7337535/439df9c6-1a0d-4a95-ba0a-3e12d0ed18ea