Skip to content

[local_auth] canCheckBiometrics returns false when Face ID permission isn't granted #160083

Closed
flutter/packages
#8348

Description

@MohsinIkram-Auxilium

Use case

I mistakenly disable the Face ID permission to my app. Now I'm unable to know how can i ask to the user you disable the permission. Basically I'm showing the Face Icon on these methods.

  Future<bool> isDeviceSupported() async {
    try {
      Debugger.log("isDeviceSupported ${await _auth.isDeviceSupported()}");
      return await _auth.isDeviceSupported();
    } catch (e) {
      Debugger.log("Error checking device support: $e");
      return false;
    }
  }

  Future<bool> canCheckBiometrics() async {
    try {
      Debugger.log("canCheckBiometrics ${await _auth.canCheckBiometrics}");
      return await _auth.canCheckBiometrics;
    } catch (e) {
      Debugger.log("Error checking biometrics: $e");
      return false;
    }
  }

isDeviceSupported this is gives me true but canCheckBiometrics this always give me false when I'm not enable the Face ID. So i just need to know how can i check if the user disbale the Face ID. so I asked him to go to setting and enable it.

Need urgent help on this.
Thanks

Proposal

  Future<bool> isDeviceSupported() async {
   try {
     Debugger.log("isDeviceSupported ${await _auth.isDeviceSupported()}");
     return await _auth.isDeviceSupported();
   } catch (e) {
     Debugger.log("Error checking device support: $e");
     return false;
   }
 }

 Future<bool> canCheckBiometrics() async {
   try {
     Debugger.log("canCheckBiometrics ${await _auth.canCheckBiometrics}");
     return await _auth.canCheckBiometrics;
   } catch (e) {
     Debugger.log("Error checking biometrics: $e");
     return false;
   }
 }

Activity

  1. maheshj01 commented on Dec 12, 2024

    @maheshj01
    Member

    Hi @MohsinIkram-Auxilium, Thanks for filing the issue. I believe you should use getAvailableBiometrics to get the list of enrolled biometrics on the device.

    Future<void> _getAvailableBiometrics() async {
        late List<BiometricType> availableBiometrics;
        try {
          availableBiometrics = await auth.getAvailableBiometrics();
        } on PlatformException catch (e) {
          availableBiometrics = <BiometricType>[];
          print(e);
        }
        if (!mounted) {
          return;
        }
    
        setState(() {
          _availableBiometrics = availableBiometrics;
        });
      }

    source: https://pub.dev/packages/local_auth/example

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 12, 2024
  3. maheshj01 commented on Dec 12, 2024

    @maheshj01
    Member

    Incase that doesn't work this could be the reason #117309

  4. MohsinIkram-Auxilium commented on Dec 12, 2024

    @MohsinIkram-Auxilium
    Author

    @maheshj01 when user not enable the Face ID then the getAvailableBiometrics list always empty.

    I have added different checks like
    1- Is Device supported the Biometrics
    2- Is getAvailableBiometrics are available or not

    I need to add check at the very top of these like User enabled the Face ID permission or not, if not then simply i would show error message to user please go to setting and enable Face ID. Thats it.

    It would be better if package developers team can add Face ID check permission. So it would be for us to show appropriate error message.
    What do you think?

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 12, 2024
  6. maheshj01 commented on Dec 12, 2024

    @maheshj01
    Member

    @MohsinIkram-Auxilium

    when user not enable the Face ID then the getAvailableBiometrics list always empty.

    getAvailableBiometrics is supposed to return the enrolled biometrics on device, meaning list of biometrics user has setup on their device. The result is empty here is because of this issue #117309

    I need to add check at the very top of these like User enabled the Face ID permission or not, if not then simply i would show error message to user please go to setting and enable Face ID. Thats it.

    I believe you should be able to detect this once the referred issue has been solved. But I agree there should be a way to detect which biometrics are enabled something like getEnabledBiometrics

    getAvailableBiometrics gives a list of enrolled biometrics but does not guarantee that the biometrics is enabled by user on device.

    Labeling this issue as a proposal to provide an api to determine if a particular biometric is enrolled and enabled to authenticate.

  7. added
    c: new featureNothing broken; request for a new capability
    p: local_authPlugin for local authentification
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Dec 12, 2024
  8. MohsinIkram-Auxilium commented on Dec 13, 2024

    @MohsinIkram-Auxilium
    Author

    Sorry I think you didn't get my point. I have a simple question. Let me clarify again.

    Lets suppose I have enrolled face and finger auth in the mobile.
    And when very first time open the Flutter IOS app, It asked me to enable Face ID like as IOS ask for Photo and location.
    When you enable the photo library then i allow us to choose images from the photo library.

    So now I disable the FaceID and trying to call again auth method. Now there is no way to check user disable the FaceID.
    So need to add check here, the user disbale the FaceID, i will show the error message "Go to settings and enable the FaceID".

    Thats it.
    I just need to check either user enable the Face ID or not.

  9. MohsinIkram-Auxilium commented on Dec 16, 2024

    @MohsinIkram-Auxilium
    Author

    @maheshj01 any update on my feedback please?

  10. maheshj01 commented on Dec 16, 2024

    @maheshj01
    Member

    So now I disable the FaceID and trying to call again auth method. Now there is no way to check user disable the FaceID.
    So need to add check here, the user disbale the FaceID, i will show the error message "Go to settings and enable the FaceID".

    @MohsinIkram-Auxilium, I have marked this issue as a proposal to have some way to know which biometric is enabled/disabled. If there are any further updates on this issue you will see them here.

  11. 6 remaining items

  12. added
    team-iosOwned by iOS platform team
    and removed
    c: proposalA detailed proposal for a change to Flutter
    on Dec 22, 2024
  13. changed the title [-][local_auth] Need to know user grant the Face ID permission or not[/-] [+][local_auth] `canCheckBiometrics` returns false when Face ID permission isn't granted[/+] on Dec 22, 2024
  14. MohsinIkram-Auxilium commented on Dec 23, 2024

    @MohsinIkram-Auxilium
    Author

    Yeah @stuartmorgan. You are right.
    There should be error messages while if any of these methods not working. So user can see appropriate message.
    Although all these functions return only Boolean value which should be changed with any error message in case of false.

  15. jmagman commented on Dec 26, 2024

    @jmagman
    Member

    I enabled FaceID in my phone settings. Then I ran the example app. When I selected "Authenticate" in the app I denied permission. Then I checked biometrics, and it returned -6 so LAErrorBiometryNotAvailable. Which is annoying because I believe that would be the same error code on a device that doesn't have biometry hardware available.

    However, a better way to detect the permission denied case might be if LAErrorBiometryNotAvailable and context.biometryType isn't LABiometryTypeNone. In my testing above it returned LABiometryTypeTouchID.

  16. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 17, 2025
  17. github-actions commented on Jan 31, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  18. locked as resolved and limited conversation to collaborators on Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p: local_authPlugin for local authentificationpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions