Skip to content

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

Closed
flutter/packages
#9981

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

Activity

  1. added
    in triagePresently being triaged by the triage team
    platform-iosiOS applications specifically
    platform-macosBuilding on or for macOS specifically
    p: local_authPlugin for local authentification
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    fyi-ecosystemFor the attention of Ecosystem team
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on Jul 10, 2024
  2. changed the title [-]local_auth: Suggestion for changes in error handling for LocalAuthentication().authenticate()[/-] [+][local_auth] Suggestion for changes in error handling for LocalAuthentication().authenticate()[/+] on Jul 16, 2024
  3. stuartmorgan-g commented on Jul 16, 2024

    @stuartmorgan-g
    Contributor

    In general we want to unify error handling across all platforms in our plugins (tracking issue for local_auth), which is a large project, but this looks like a case where we could incrementally make this specific change without a breaking change, so would be good to do in the short term.

  4. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Jul 31, 2024
  5. github-actions commented on Oct 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.

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

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-macosBuilding 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