chore: update documentation

This commit is contained in:
Lucas Nogueira
2026-09-22 11:30:47 -03:00
parent d869c162a7
commit a87a3c7d44
104 changed files with 4875 additions and 222 deletions
+47 -7
View File
@@ -2,22 +2,40 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Prompt the user for biometric authentication on Android and iOS.
*
* @module
*/
import { invoke } from '@tauri-apps/api/core'
/**
* The kind of biometry hardware detected on the device.
*/
export enum BiometryType {
/** No biometry hardware is available, or it is not enrolled with the operating system. */
None = 0,
// Apple TouchID or Android fingerprint
/** Apple TouchID or Android fingerprint. */
TouchID = 1,
// Apple FaceID or Android face authentication
/** Apple FaceID or Android face authentication. */
FaceID = 2,
// Android iris authentication
/** Android iris authentication. */
Iris = 3
}
/**
* The result of {@linkcode checkStatus}, describing whether biometric authentication can
* currently be used.
*/
export interface Status {
/** Whether the device can currently authenticate using biometrics. */
isAvailable: boolean
/** The kind of biometry hardware detected on the device, even when {@linkcode isAvailable} is `false`. */
biometryType: BiometryType
/** A human-readable reason why biometric authentication is unavailable. Only set when {@linkcode isAvailable} is `false`. */
error?: string
/** A platform-specific error code describing why biometric authentication is unavailable. Only set when {@linkcode isAvailable} is `false`. */
errorCode?:
| 'appCancel'
| 'authenticationFailed'
@@ -32,23 +50,43 @@ export interface Status {
| 'biometryNotEnrolled'
}
/**
* Options for the {@linkcode authenticate} biometric prompt.
*/
export interface AuthOptions {
/** Enables authentication using the device's password or PIN. Available on both Android and iOS. */
allowDeviceCredential?: boolean
/** Label for the cancel button. Available on both Android and iOS. */
cancelTitle?: string
// iOS options
/** Text displayed on the fallback button if biometric authentication fails. **iOS only.** */
fallbackTitle?: string
// android options
/** Title indicating the purpose of the biometric verification. **Android only.** */
title?: string
/** Subtitle providing contextual information of the biometric verification. **Android only.** */
subtitle?: string
/** Whether additional user confirmation is required, such as pressing a button, after successful biometric authentication. **Android only.** */
confirmationRequired?: boolean
/** Maximum number of attempts allowed before the prompt is dismissed. Defaults to `3`. **Android only.** */
maxAttemps?: number
}
/**
* Checks if the biometric authentication is available.
* @example
* ```typescript
* import { checkStatus } from '@tauri-apps/plugin-biometric';
*
* const status = await checkStatus();
* if (status.isAvailable) {
* // do something
* }
* ```
* @returns a promise resolving to an object containing all the information about the status of the biometry.
* @since 2.0.0
*/
export async function checkStatus(): Promise<Status> {
return await invoke('plugin:biometric|status')
@@ -58,13 +96,15 @@ export async function checkStatus(): Promise<Status> {
* Prompts the user for authentication using the system interface (touchID, faceID or Android Iris).
* Rejects if the authentication fails.
*
* ```javascript
* @example
* ```typescript
* import { authenticate } from "@tauri-apps/plugin-biometric";
* await authenticate('Open your wallet');
* ```
* @param reason
* @param options
* @returns
* @param reason A message shown to the user explaining why authentication is requested.
* @param options Configuration for the biometric prompt.
* @returns a promise resolving to `void` once the user is successfully authenticated.
* @since 2.0.0
*/
export async function authenticate(
reason: string,
+6
View File
@@ -4,12 +4,18 @@
use serde::{ser::Serializer, Serialize};
/// Alias for a [`Result`](std::result::Result) with the error type [`Error`].
pub type Result<T> = std::result::Result<T, Error>;
/// The error types returned by this plugin.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// An I/O error occurred.
#[error(transparent)]
Io(#[from] std::io::Error),
/// The invocation of the underlying Android or iOS plugin failed, for example because
/// biometric authentication was unavailable, was not enrolled, failed, or was canceled by
/// the user.
#[cfg(mobile)]
#[error(transparent)]
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
+11
View File
@@ -2,6 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Prompt the user for biometric authentication.
//!
//! - Supported platforms: Android and iOS.
#![cfg(mobile)]
use serde::Serialize;
@@ -34,10 +38,16 @@ struct AuthenticatePayload {
}
impl<R: Runtime> Biometric<R> {
/// Checks the device's availability and type of biometric authentication, as reported by the
/// operating system. Errors if the underlying mobile plugin invocation fails.
pub fn status(&self) -> crate::Result<Status> {
self.0.run_mobile_plugin("status", ()).map_err(Into::into)
}
/// Prompts the user for biometric authentication using the system UI (Android
/// `BiometricPrompt` or iOS `LocalAuthentication`), showing `reason` as the purpose of the
/// request. Resolves once the user is authenticated and errors if authentication fails, is
/// canceled, or the underlying mobile plugin invocation fails.
pub fn authenticate(&self, reason: String, options: AuthOptions) -> crate::Result<()> {
self.0
.run_mobile_plugin("authenticate", AuthenticatePayload { reason, options })
@@ -47,6 +57,7 @@ impl<R: Runtime> Biometric<R> {
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the biometric APIs.
pub trait BiometricExt<R: Runtime> {
/// Returns the [`Biometric`] instance managed by the app.
fn biometric(&self) -> &Biometric<R>;
}
+13
View File
@@ -4,6 +4,7 @@
use serde::{Deserialize, Serialize};
/// Options for [`Biometric::authenticate`](crate::Biometric::authenticate).
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthOptions {
@@ -21,19 +22,31 @@ pub struct AuthOptions {
pub confirmation_required: Option<bool>,
}
/// The kind of biometry hardware detected on the device.
#[derive(Debug, Clone, serde_repr::Deserialize_repr)]
#[repr(u8)]
pub enum BiometryType {
/// No biometry hardware is available, or it is not enrolled with the operating system.
None = 0,
/// Fingerprint authentication (Apple Touch ID or Android fingerprint).
TouchID = 1,
/// Face authentication (Apple Face ID or Android face authentication).
FaceID = 2,
}
/// The result of [`Biometric::status`](crate::Biometric::status), describing whether biometric
/// authentication can currently be used.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Status {
/// Whether the device can currently authenticate using biometrics.
pub is_available: bool,
/// The kind of biometry hardware detected on the device, even when [`Self::is_available`] is `false`.
pub biometry_type: BiometryType,
/// A human-readable reason why biometric authentication is unavailable. Only set when
/// [`Self::is_available`] is `false`.
pub error: Option<String>,
/// A platform-specific error code describing why biometric authentication is unavailable.
/// Only set when [`Self::is_available`] is `false`.
pub error_code: Option<String>,
}