authenticateWithAutocompletion method

Future<SignInHandler> authenticateWithAutocompletion({
  1. required Request request,
  2. required Future<void> callback(
    1. Response
    ),
})

Sign in an existing user using a passkey. While authenticateWithEmail can also be used to do this authenticateWithAutocompletion is the better way and should be used by default because it is more convenient for the user.

authenticateWithAutocompletion should be called when the sign in page is loaded and before any user interaction has happened. It returns a SignInHandler. Call .complete on this handler as soon as the user focuses the username input field. Now the user will be shown a list of all available passkeys and he can complete the sign in flow.

Implementation

Future<SignInHandler> authenticateWithAutocompletion({
  required Request request,
  required Future<void> Function(Response) callback,
}) async {
  final initResponse =
      await _backend.initAuthenticateWithAutoComplete(request);

  return SignInHandler(
    complete: (void Function(Exception)? onError) async {
      try {
        final completeResponse = await _completeSignIn(initResponse);
        await callback(completeResponse);
      } on Exception catch (e) {
        if (onError == null) {
          return;
        }

        onError(e);
      }
    },
  );
}