Biometric Authentication

This guide will help you add native biometric verification (Face ID, fingerprint) to your WeWeb mobile application using Despia.

Overview

There are two ways to implement biometric authentication:

  1. JavaScript SDK - For in-app verification at specific points

  2. Biometric App Lock - Blocks entire app access until authenticated

Important: Biometric authentication is a security enhancement, not a replacement for proper backend authentication (Supabase, Xano, etc.). Think of it as an additional layer of security on top of your existing authentication system.

The simplest and most secure method requires no code setup in WeWeb.

Setup Steps:

  1. Open your Despia editor

  2. Navigate to Add-ons

  3. Enable Biometric App Lock

  4. Rebuild your application

This completely blocks app access until the user verifies their biometric credentials or device passcode.

Method 2: JavaScript SDK Implementation

Use this method for specific in-app verification points (e.g., before sensitive actions).

1

Create Page Workflow

  1. In WeWeb, go to your page settings (steering wheel icon)

  2. Navigate to Trigger Page Workflows

  3. Create a new workflow named Start Biometric Despia SDK

2

Add SDK Initialization

Add a Custom JavaScript action named "Attach Global Functions for Callback" with the following code:

// Attach Global Functions for Callback
if (!document.getElementById("bioauth-sdk")) {
    const script = document.createElement("script")
    script.id = "bioauth-sdk"
    script.type = "text/javascript"
    script.textContent = `
        function onBioAuthSuccess() {
            window.bioauthSuccess()
        }
        function onBioAuthFailure(errorCode, errorMessage) {
            window.bioauthFailure(errorCode, errorMessage)
        }
        function onBioAuthUnavailable() {
            window.bioauthUnavailable()
        }
    `
    document.head.appendChild(script)
}
3

Register Callback Functions

Add another Custom JavaScript action named "Register Window Callback Functions" to register the callback handlers:

// Register Window Callback Functions
const wwBiometricWorkflowID = "YOUR_WORKFLOW_ID" // Replace with your actual workflow ID

window.bioauthSuccess = function () {
    if (navigator.userAgent.includes("despia")) {
        wwLib.wwWorkflow.executeGlobal(wwBiometricWorkflowID, {
            "method": "success",
            "errorCode": null,
            "errorMessage": null
        })
    }
}

window.bioauthFailure = function (errorCode, errorMessage) {
    if (navigator.userAgent.includes("despia")) {
        wwLib.wwWorkflow.executeGlobal(wwBiometricWorkflowID, {
            "method": "failure",
            "errorCode": errorCode,
            "errorMessage": errorMessage
        })
    }
}

window.bioauthUnavailable = function () {
    if (navigator.userAgent.includes("despia")) {
        wwLib.wwWorkflow.executeGlobal(wwBiometricWorkflowID, {
            "method": "unavailable",
            "errorCode": null,
            "errorMessage": null
        })
    }
}
4

Create Callback Handler Workflow

  1. In WeWeb's Logic panel, create a new Global Workflow

  2. Name it Despia Biometric Callback Handler

  3. Set it to run On Execution

  4. Add the following parameters:

Parameter

Type

Example Value

method

String

"success"

errorCode

Number

200

errorMessage

Text

"All working fine"

  1. Important: Copy this workflow's ID and replace YOUR_WORKFLOW_ID in Step 3
5

Handle Authentication Results

In your callback handler workflow, add a Multi-Option Split with three branches:

Success Branch

  • Condition: method equals "success"

  • Actions:

    • Redirect to protected content

    • Continue with sensitive action

    • Refresh authentication token

Failure Branch

  • Condition: method equals "failure"

  • Actions:

    • Show error alert: "Authentication failed"

    • Log security event

    • Optionally lock after multiple failures

Unavailable Branch

  • Condition: method equals "unavailable"

  • Actions:

    • Provide fallback authentication method

    • Show message: "Biometric authentication not available"

    • Request password or PIN

6

Trigger Biometric Authentication

Create a button or workflow action to trigger biometric verification:

  1. Add a button element to your page

  2. Create a workflow on button click

  3. Add a Custom JavaScript action named "Run Despia Biometric SDK":

// Run Despia Biometric SDK
window.despia = "bioauth://"

Complete Implementation Example

Page Workflow Structure

Start Biometric Despia SDK (On Page Load)
├── Attach Global Functions for Callback
└── Register Window Callback Functions

Global Workflow Structure

Despia Biometric Callback Handler
└── Multi-Option Split (based on method parameter)
    ├── Success → Execute success actions
    ├── Failure → Show error message
    └── Unavailable → Provide fallback

Use Cases

Secure Sections

Protect sensitive areas like customer data or financial information:

// On button click to access leads section
window.despia = "bioauth://"
// Success callback redirects to protected content

Confirm Critical Actions

Require biometric verification before:

  • Logging out

  • Making transfers

  • Deleting data

  • Posting content

  • Accessing personal information

Session Extension

Use successful biometric authentication to refresh user tokens:

// In success callback
// Call API to refresh token
// Extend session validity by 30 days

Platform Support

iOS

  • Full support for Face ID

  • Full support for Touch ID

  • Fallback to device passcode

Android

  • Biometric App Lock: Works on 99% of devices

  • JavaScript SDK: Limited support on some devices

  • Automatic fallback to device passcode

Security Considerations

Important Security Notes

  1. Client-side protection only

    • Prevents casual unauthorized access

    • Tech-savvy users could bypass through browser console

    • Not suitable as sole security measure

  2. Backend security required

    • Always implement proper server-side authentication

    • Use this as an additional layer, not a replacement

    • Validate all sensitive operations server-side

  3. User agent verification

    • The navigator.userAgent.includes("despia") check ensures code only runs in native app

    • Prevents execution in web browsers

    • Can be spoofed by determined attackers

  4. Physical security focus

    • Best for preventing unauthorized access to unlocked devices

    • Protects against someone grabbing an unlocked phone

    • Not protection against remote attacks

Testing Your Implementation

Test Scenarios

  1. Successful Authentication

    • User provides correct biometric

    • Verify success callback executes

    • Check that protected content becomes accessible

  2. Failed Authentication

    • User provides incorrect biometric

    • Verify failure callback executes

    • Confirm error message displays

  3. Cancelled Authentication

    • User cancels biometric prompt

    • Should trigger failure callback

    • Application should remain secure

  4. Unavailable Biometric

    • Test on device without biometric support

    • Verify unavailable callback executes

    • Check fallback method works

Testing Steps

  1. Deploy your WeWeb application

  2. Build in Despia editor

  3. Install through TestFlight (iOS) or equivalent (Android)

  4. Test each scenario above

  5. Verify callbacks work correctly

  6. Test on multiple device types

Troubleshooting

Common Issues and Solutions

Issue

Solution

Android devices not working

Use Biometric App Lock instead of JavaScript SDK

Workflow not triggering

Verify workflow ID is correct and set to "On Execution"

Functions undefined error

Ensure SDK initialization runs on page load

Callbacks not executing

Check user agent verification is working

Multiple prompts appearing

Ensure you're not calling window.despia = "bioauth://" multiple times

Summary

Biometric authentication with Despia adds a valuable security layer to your WeWeb mobile applications. While not a replacement for backend security, it significantly improves the user experience and provides protection against casual unauthorized access. Choose between the simple Biometric App Lock for maximum security or the flexible JavaScript SDK for targeted protection of specific features.

Remember: This is a security enhancement, not a security foundation. Always implement proper backend authentication and validation for all sensitive operations.

Updated on