Skip to content

[local_auth] Suggestion for changes in error handling for LocalAuthentication().authenticate() #151513

@TakuyaHida

Description

@TakuyaHida

Use case

I'd like to suggest some changes to the error handling for the biometric authentication features provided by the local_auth library.
Currently, there are some differences in how errors are handled on iOS and Android.
I'm particularly focused on one specific situation on iOS: when iOS biometric authentication is voluntarily cancelled by the user.

Proposal

  • For cases when iOS biometric authentication is voluntarily cancelled by the user:

Currently, when a user voluntarily cancels the iOS biometric authentication, a PlatformException with error PlatformException(NotAvailable, Authentication canceled., com.apple.LocalAuthentication, null) is returned on Flutter's end. 

Simulator Screenshot - iPhone SE (3rd generation) - 2024-07-10 at 11 45 40

This PlatformException is indistinguishable from the PlatformException(NotAvailable, Authentication failure., com.apple.LocalAuthentication, null) returned when biometric authentication fails consecutively.
This makes it difficult to properly handle each exception.

However, on Android, when a user voluntarily cancels the authentication, the return value of LocalAuthentication().authenticate() is false.
Therefore, to make it easier to differentiate between the two exceptions, I propose that for voluntarily cancelled iOS biometric authentication, like Android, the return value of LocalAuthentication().authenticate() should be false.
I believe that this can be achieved by adding kLAErrorUserCancel to the iOS source code.

I believe that the issue could be resolved by writing a code as follows.
スクリーンショット 2024-07-09 18 57 11

Metadata

Metadata

Labels

P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterp: local_authPlugin for local authentificationpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyplatform-macBuilding on or for macOS specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions