flutter icon indicating copy to clipboard operation
flutter copied to clipboard

[local_auth] Need to know user grant the Face ID permission or not

Open MohsinIkram-Auxilium opened this issue 11 months ago • 9 comments
trafficstars

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;
   }
 }

MohsinIkram-Auxilium avatar Dec 11 '24 11:12 MohsinIkram-Auxilium

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

maheshj01 avatar Dec 12 '24 00:12 maheshj01

Incase that doesn't work this could be the reason https://github.com/flutter/flutter/issues/117309

maheshj01 avatar Dec 12 '24 00:12 maheshj01

@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?

MohsinIkram-Auxilium avatar Dec 12 '24 07:12 MohsinIkram-Auxilium

@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.

maheshj01 avatar Dec 12 '24 21:12 maheshj01

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.

MohsinIkram-Auxilium avatar Dec 13 '24 07:12 MohsinIkram-Auxilium

@maheshj01 any update on my feedback please?

MohsinIkram-Auxilium avatar Dec 16 '24 13:12 MohsinIkram-Auxilium

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.

maheshj01 avatar Dec 16 '24 22:12 maheshj01

Thanks @maheshj01. Waiting for your response because our app going to be live in this week with Auth feature. So we need to give best user experience to our daily users.

MohsinIkram-Auxilium avatar Dec 17 '24 07:12 MohsinIkram-Auxilium

I was faced with unpredictable behavior. Sometimes the canCheckBiometrics method returns "false" even when everything is enabled and configured. And for some reason, after some time it returns "true" again

nickolight avatar Dec 20 '24 14:12 nickolight

isDeviceSupported this is gives me true but canCheckBiometrics this always give me false when I'm not enable the Face ID.

This is a bug; canCheckBiometrics should be returning true in this case (per the README, this is intended to indicate that the hardware supports biometrics). The combination of canCheckBiometrics being true and the list of available biometrics being enrolled being empty is how developers are intended to detect a case like this.

Someone will need to see what error is returned in this code when the permission isn't granted, and we can special-case it.

stuartmorgan-g avatar Dec 22 '24 15:12 stuartmorgan-g

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.

MohsinIkram-Auxilium avatar Dec 23 '24 07:12 MohsinIkram-Auxilium

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.

jmagman avatar Dec 26 '24 21:12 jmagman

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.

github-actions[bot] avatar Jan 31 '25 21:01 github-actions[bot]