Official Integration Guide For Websites & Apps

Integrate the fio.js JavaScript library and FACEIO Widget into your website or web app. Use enroll() to register new users and authenticate() to sign returning users in with facial authentication.

quick-start.js
JavaScript
// 1. Add to your HTML before </body>
<div id="faceio-modal"></div>
<script src="https://cdn.faceio.net/fio.js"></script>

// 2. Instantiate with your Public ID
const faceio = new faceIO("app-public-id");

// 3. Enroll a new user
faceio.enroll({ "locale": "auto",
         "payload": { "email": "user@example.com" }
}).then(userInfo => {
  console.log(`Enrolled: ${userInfo.facialId}`);
}).catch(err => handleError(err));

// 4. Authenticate a returning user
faceio.authenticate({ "locale": "auto" })
.then(userData => {
  console.log("Payload:", JSON.stringify(userData.payload));
}).catch(err => handleError(err));

What is FACEIO?

FACEIO is a facial authentication platform from PixLab ↗ that lets a web application enroll and authenticate users by face without requiring passwords, OTPs, or dedicated biometric sensors in the FACEIO flow. It uses a standard webcam or smartphone camera in supported modern browsers.

The client-side library is fio.js. It exposes two primary methods: enroll() for registration and authenticate() for sign-in, plus a restartSession() utility for multi-operation flows. FACEIO coordinates the authentication flow while the facial recognition engine selected by the application owner performs facial matching and manages biometric hashes. Your application receives a resolved Promise with the user's Facial ID and any payload data you attached at enrollment.

New to FACEIO?

Start with the 5-Minute Setup Guide to create your first application and get your Public ID from the FACEIO Console ↗.


fio.js Library Integration

fio.js works in supported modern browsers with a standard webcam or smartphone camera, with no dedicated biometric sensor required. The JavaScript library is framework-agnostic and can be used with React, Vue, Angular, Next.js, or plain JavaScript.

1 Import fio.js to Your Site

Paste the following snippet before the closing </body> tag on any page where you want facial authentication. The library is loaded from FACEIO's CDN ↗ . Self-hosting is not supported, so integrations receive supported fio.js updates from the FACEIO CDN.

index.html
HTML
<div id="faceio-modal"></div>
<script src="https://cdn.faceio.net/fio.js"></script>

2 Instantiate a faceIO Object

Instantiate faceIO() with your application's Public ID. This ID is available in the Application Manager on the FACEIO Console ↗.

app.js
JavaScript
<script type="text/javascript">
  /* Instantiate fio.js with your application's Public ID */
  const faceio = new faceIO("app-public-id");
</script>

Before you continue, make sure you have:

3 Invoke the Widget

With fio.js loaded and your faceIO() instance ready, start the facial recognition process by calling either method exposed by the class:

enroll()

Registers a new user via face recognition. The passwordless equivalent of a traditional sign-up.

authenticate()

Authenticates a previously enrolled user. The passwordless equivalent of a traditional sign-in.

app.js
JavaScript
<button onclick="enrollNewUser()">Enroll New User</button>
<button onclick="authenticateUser()">Authenticate User</button>

<script type="text/javascript">
  const faceio = new faceIO("app-public-id");

  function enrollNewUser() {
    // Calling faceio.enroll() triggers the enrollment flow
  }

  function authenticateUser() {
    // Calling faceio.authenticate() triggers the authentication flow
  }

  function handleError(errCode) {
    // Handle error here
  }
</script>

Reference Template

The HTML Boilerplate section provides a complete reference implementation with both methods and full error handling wired up.


enroll() - Enroll New User

Triggers the FACEIO Widget to register a new user with face recognition. This is the passwordless equivalent of a traditional sign-up flow. On success, returns a Promise resolving with a userInfo object containing the user's unique Facial ID, enrollment timestamp, and demographic estimates including gender and age.

Syntax

Signature
promise = faceio.enroll({ parameters })
Alias
enrol() register() record()
Returns
A Promise that resolves with a userInfo object on success, or rejects with a fioErrCode on failure.

Description

Behavior

When called, the FACEIO Widget requests user consent when required, asks for camera access, and submits the capture to the facial recognition engine selected by the application owner using only two frames, making it extremely bandwidth-efficient.

FACEIO does not store, handle, or access biometric hashes. The selected facial recognition engine creates and manages the biometric hashes used for matching, while your integration receives the resulting Facial ID and enrollment data.

PIN
During enrollment, users set a 4-16 digit PIN. It may be required on future authentication if a face collision occurs, match confidence falls slightly below 99%, or your app enforces PIN confirmation.
Payload
The payload parameter attaches arbitrary data (email, userId, name, etc.) to the enrolled user. This data is returned upon every successful authentication of that user. Max size: 16 KB; Base64-encode any non-ASCII or binary content.
Webhook
If you have configured a Webhook, FACEIO will POST enrollment data to your endpoint for real-time backend synchronization.

Parameters

Accepts a single optional object. All properties are optional:

Property Type Default Description
payload JSON null Arbitrary data to associate with this user, returned on future authentications. Max 16 KB. Base64-encode non-ASCII data.
permissionTimeout Number 27 sec Seconds to wait for camera permission. Aborts with fioErrCode.PERMISSION_REFUSED on timeout.
termsTimeout Number 10 min Minutes to wait for Terms of Service acceptance. Aborts with fioErrCode.TERMS_NOT_ACCEPTED on timeout.
idleTimeout Number 27 sec Seconds to wait if no face is detected. Aborts with fioErrCode.NO_FACES_DETECTED on timeout.
replyTimeout Number 40 sec Seconds to wait for a server response. Aborts with fioErrCode.TIMEOUT on timeout.
enrollIntroTimeout Number 12 sec Seconds to display the enrollment introduction/instruction screen.
locale String auto Widget language. auto detects from the browser; or pass a BCP 47 code (en, ar, es, ja, de-). Falls back to en-US if unsupported.
userConsent Boolean false Set to true if you have already obtained user consent (e.g., during account creation). Skips the Terms of Service consent screen. It is your responsibility to explicitly ask for consent before enrolling a new user. See Privacy Best Practices.
showAbortBtn Boolean false Set to true to always show the close/abort button. If the user clicks it, fioErrCode.ABORTED_BY_USER is raised.

Return Value

userInfo

A Promise resolving with a userInfo object on success, or rejecting with an error code on failure:

Property Type Description
facialId String (UUID) Unique identifier assigned by the facial recognition engine. See Facial ID.
timestamp String ISO 8601 ↗ enrollment completion timestamp.
details Object Contains gender and age estimates for the enrolled user.

Example

Usage
app.js
JavaScript
// Instantiate fio.js with your application's Public ID
const faceio = new faceIO("app-public-id");
function enrollNewUser(){
faceio.enroll({
  "locale": "auto", // Default user locale
  "payload": {
      /* The payload we want to associate with this particular user which is forwarded back to us upon future authentication of this user.*/
      "whoami": 123456, // Dummy ID linked to this particular user
      "email": "john.doe@example.com"
      }
  }).then(userInfo => {
      // User Successfully Enrolled! 
      alert(
          `User Successfully Enrolled! Details:
           Unique Facial ID: ${userInfo.facialId}
           Enrollment Date: ${userInfo.timestamp}
           Gender: ${userInfo.details.gender}
           Age Approximation: ${userInfo.details.age}`
      );
     console.log(userInfo);
     // handle success, save the facial ID (userInfo.facialId), redirect to the dashboard...
  }).catch(errCode => {
     // Something went wrong during enrollment, log the failure
     handleError(errCode);
  })
}
Notes
  • Store the returned facialId in your database as the user's unique authentication key.
  • The payload is echoed back verbatim on every future authenticate() call for this user.
  • See the HTML Boilerplate for a full working reference.

authenticate() - Authenticate User

Triggers the FACEIO Widget to verify a previously enrolled user. This is the passwordless equivalent of a traditional sign-in flow. On success, returns a Promise resolving with a userData object containing the user's Facial ID, authentication timestamp, and the payload attached at enrollment.

Syntax

Signature
promise = faceio.authenticate({ parameters })
Alias
auth() recognize() identify()
Returns
A Promise that resolves with a userData object on success, or rejects with a fioErrCode on failure.

Description

Behavior

When called, the FACEIO Widget prompts for camera access and compares the capture with the enrolled face index for your application. Capture length depends on camera permission, image quality, liveness checks, network conditions, and the configured flow.

Facial matching is performed by the selected facial recognition engine. FACEIO does not store, handle, or access biometric hashes, and your client-side integration works with the returned authentication result.

PIN
A PIN challenge may be presented if: a face collision is detected, match confidence is slightly below 99%, or your application enforces PIN confirmation via Security Options in the FACEIO Console.
Payload
The payload data attached during enroll() is returned verbatim inside the resolved userData object. Validate the returned facialId and apply your own server-side authorization rules before creating an application session.
Webhook
If a Webhook is configured, FACEIO POSTs authentication event data to your endpoint immediately after a successful authentication.

Parameters

Accepts a single optional object. All properties are optional:

Property Type Default Description
permissionTimeout Number 27 sec Seconds to wait for camera permission. Aborts with fioErrCode.PERMISSION_REFUSED on timeout.
idleTimeout Number 27 sec Seconds to wait if no face is detected. Aborts with fioErrCode.NO_FACES_DETECTED on timeout.
replyTimeout Number 40 sec Seconds to wait for a server response. Aborts with fioErrCode.TIMEOUT on timeout.
locale String auto Widget language. auto detects from the browser; or pass a BCP 47 code (en, ar, es, ja, de-). Falls back to en-US.

Return Value

userData

A Promise resolving with a userData object on success, or rejecting with an error code on failure:

Property Type Description
facialId String (UUID) Unique identifier assigned during enrollment. See Facial ID documentation.
payload Any The arbitrary data you linked to this user during enrollment (email, userId, etc.).

Example

Usage
app.js
JavaScript
const faceio = new faceIO("app-public-id"); // Initialize with your application's Public ID
function authenticateUser(){
  faceio.authenticate({
      "locale": "auto" // Default user locale
  }).then(userData => {
      console.log("Success, user identified")
      // Grab the facial ID linked to this particular user which will be same
      // for each of his successful future authentication. FACEIO recommend 
      // that you rely on this Facial ID if you plan to uniquely identify 
      // all enrolled users on your backend for example.
      console.log("Linked facial Id: " + userData.facialId)
      // Grab the arbitrary data you have already linked (if any) to this particular user
      // during his enrollment via the payload parameter of the enroll() method.
      console.log("Payload: " + JSON.stringify(userData.payload)) // {"whoami": 123456, "email": "john.doe@example.com"} from the enroll() example above
  }).catch(errCode => {
      handleError(errCode)
  })
}
Notes
  • Compare the returned facialId against your database to authorize the session.
  • The enrollment payload (e.g. email, userId) is available in userData.payload - no extra DB lookup needed.
  • See the HTML Boilerplate for a complete wired-up reference.

restartSession() - Restart Session

Resets the current FACEIO session so that a new enroll() or authenticate() call can be made on the same page without a full page reload. Useful for multi-user flows such as kiosk terminals, event check-in stations, or any scenario where multiple people use the same browser session sequentially.

Syntax

Signature
boolean = faceio.restartSession()
Parameters
None. This method takes no arguments.
Returns
true when the session is successfully reset and ready for a new operation; otherwise false.

Description

Behavior

Once enroll() or authenticate() resolves (or rejects), the internal FACEIO session is marked as consumed. Any subsequent call to either method on the same faceIO instance without resetting will reject immediately with fioErrCode.SESSION_IN_PROGRESS.

Calling restartSession() clears this state, making the instance ready for another recognition operation.

Use Cases
  • Kiosk / shared terminal - Let multiple users authenticate sequentially on the same device without a page reload.
  • Enroll-then-authenticate flow - Enroll a new user, then immediately authenticate them on the same page to confirm successful enrollment.
  • Retry after error - Reset after a failed operation so the user can try again without refreshing.
Scope
The reset is scoped to the single faceIO instance. If you have instantiated multiple faceIO objects (not recommended), each has its own independent session state.
Premium Feature

Dynamic session generation is available to Premium Plans only. Upgrade your application from the FACEIO Console ↗ to use this feature.

Return Value

Success
true - session was successfully cleared and the instance is ready for a new enroll() or authenticate() call.
Failure
false when a new session could not be created.

Error Codes - fioErrCode

When enroll() or authenticate() fail, the Promise rejects with a numeric fioErrCode value. Handle errors by switching on this value inside your .catch() handler. For restartSession(), check the returned boolean (true or false).

Code Constant Description
1 fioErrCode.PERMISSION_REFUSED The end-user denied camera access. Prompt them to allow it in browser settings.
2 fioErrCode.NO_FACES_DETECTED No face was detected within the idle timeout period. Ask the user to reposition and retry.
3 fioErrCode.UNRECOGNIZED_FACE The scanned face did not match any enrolled user in your application's database. Authentication only.
4 fioErrCode.MANY_FACES Multiple faces were detected simultaneously. Only one face must be in frame.
5 fioErrCode.FACE_DUPLICATION User is attempting to enroll again but their face is already registered. This occurs when the "Prevent Same User from Enrolling Twice" security setting is enabled in the FACEIO Console ↗. Enrollment aborted; guide user to authenticate instead.
6 fioErrCode.MINORS_NOT_ALLOWED Enrollment was rejected by the configured minimum-age policy. Display an appropriate age-restriction message and follow the application owner's access policy.
7 fioErrCode.PAD_ATTACK A suspected presentation attack was detected, such as a photo, video replay, or mask presented instead of a live face. Treat this as a security signal, apply your retry or review policy, and do not assume any anti-spoofing system detects every attempt. Learn more about liveness detection ↗.
8 fioErrCode.FACE_MISMATCH Facial vectors captured during enrollment did not match one another. Only raised during enroll(). Ask the user to retry enrollment.
9 fioErrCode.NETWORK_IO A network error occurred. Check connectivity and retry.
10 fioErrCode.WRONG_PIN_CODE Incorrect PIN code entered during authentication. Only raised during authenticate(). Aborted after 3 failed attempts. Allow user to retry authentication.
11 fioErrCode.PROCESSING_ERR Internal server error. The condition may be temporary; retry the operation after a short delay.
12 fioErrCode.UNAUTHORIZED The Public ID is invalid, or the application has not been activated in the FACEIO Console.
13 fioErrCode.TERMS_NOT_ACCEPTED The user did not accept the Terms of Service within termsTimeout. Enrollment only.
14 fioErrCode.UI_NOT_READY The FACEIO Widget has not finished initializing. Wait for the DOM to be fully loaded before invoking any method.
15 fioErrCode.UNIQUE_PIN_REQUIRED PIN code must be unique across all users when PIN uniqueness enforcement is enabled.
16 fioErrCode.TIMEOUT Server did not respond within replyTimeout. Check connectivity and retry.
17 fioErrCode.TOO_MANY_REQUESTS Rate limit exceeded. Implement exponential back-off before retrying.
18 fioErrCode.EMPTY_ORIGIN The request origin header is missing. Ensure fio.js is served from a valid domain.
19 fioErrCode.FORBIDDEN_ORIGIN The request origin is not on the allowlist. Add your domain in FACEIO Console Security Options.
20 fioErrCode.FORBIDDEN_COUNTRY The user's country is blocked by your application's geographic restrictions in the FACEIO Console.
21 fioErrCode.SESSION_IN_PROGRESS Another enrollment or authentication is already in progress. This can occur if enroll() or authenticate() is called multiple times, such as after a double-click. Use restartSession() to start a new session without reloading the page. If the Widget is still running, handle this state without starting another operation.
22 fioErrCode.ABORTED_BY_USER The user clicked the abort/close button (only possible when showAbortBtn: true).

Error Handling Best Practice

Always implement comprehensive error handling with user-friendly messages. Use a switch statement or if-else chain to handle specific error codes and guide users appropriately (e.g. prompt enrollment when fioErrCode.UNRECOGNIZED_FACE is returned).


HTML Boilerplate

A complete reference implementation with both enroll() and authenticate() fully wired with error handling. Use it as a starting point for your integration.

Important

Replace app-public-id with your real application Public ID from the FACEIO Console ↗.

Reference Template

Implementation Notes

  • The enroll() call (line 31) includes a payload with sample user data. Customize this to match your application's needs.
  • Store the returned facialId in your database and link it to the user's account for future authentication lookups.
  • The error handler (line 60) covers all common error codes. Customize the messages to match your application's tone.
  • This boilerplate requires a running HTTP server. fio.js cannot be loaded directly from the local file system due to browser security restrictions.
  • Review our Security Best Practices and Privacy Best Practices guides before deploying to production.

Community Tutorials

Use these community-contributed guides to implement fio.js with React, Vue, Angular, Next.js, or plain JavaScript, and to review community examples for React Native and Flutter projects.

Official NPM Package

Official package for JavaScript build tools and framework-based projects.

View on NPM
Community Forum

Get answers, share experiences, and connect with other FACEIO developers.

Join Forum
Privacy-First Passwordless Auth

Comprehensive guide covering passwordless login, age verification, and liveness detection in one stack.

View Tutorial
Facial Attendance System (Vanilla JS)

Build an attendance flow using FACEIO and plain JavaScript without a framework.

View Tutorial
AI Chatbot with Facial Auth (Next.js)

Build an AI vacation planner chatbot with secure facial authentication using Next.js.

View Tutorial
Facial Recognition with React & Tailwind

Replace traditional authentication with facial recognition in a React + Tailwind CSS application.

View Tutorial
Face Recognition in Vue.js

Complete tutorial on implementing FACEIO facial authentication in a Vue.js application.

View Tutorial
Authenticate Users in React (freeCodeCamp)

Step-by-step freeCodeCamp guide to adding face recognition authentication to a React app.

View Tutorial
Modern Web Authentication Patterns

Explore modern authentication patterns for web apps using facial recognition technology.

View Tutorial
Ultimate Guide to FACEIO

A comprehensive deep-dive covering all aspects of FACEIO implementation and best practices.

View Tutorial
Face Recognition Login (Vanilla JS)

Build a face recognition login flow with plain JavaScript and no framework.

View Tutorial
Streamline Attendance Tracking

Build an efficient attendance monitoring system powered by FACEIO's facial recognition.

View Tutorial
Have a Tutorial to Share?

Share a FACEIO implementation tutorial with the developer community.

Contact Us

Integrate FACEIO in 5 Minutes

Create a FACEIO application, copy its Public ID, load fio.js, and connect enroll() and authenticate() to your registration and sign-in controls.

No Credit Card Required
5-Minute Integration
Framework Agnostic