1. Home
  2. Docs
  3. NPM package
  4. Basic Usage
  5. Getting started

Getting started

Setup Instructions

This section offers a comprehensive guide on integrating the @face-auth/face-id package into a project from the ground up. Follow these steps to set up your environment, install dependencies, and prepare your project for effective use of the package.

Set Up Your Environment:

Ensure that Node.js and npm are installed on your system. Create a new project directory and navigate into it using your terminal.

Install Dependencies:

Run the following command to install the @face-auth/face-id package:

npm install @face-auth/face-id

Bash

Prepare Your Project:

  • Create a configuration file (e.g., .env) to store your domain and client token securely.
  • Ensure you have access to the credentials required for initialization (domain and client token).

Initialization

o properly configure and initialize the @face-auth/face-id package, follow these detailed instructions:

Import the Package

In your JavaScript file, import the package using require (for CommonJS) or import (for ES6 modules):

Using CommonJS (require)

// Import the package using CommonJS
const FaceId = require('@face-auth/face-id');

TypeScript

This syntax is used in environments like Node.js. The require function is used to import the FaceId class from the @face-auth/face-id package.

Using ES6 Modules (import)

// Import the package using ES6 modules
import FaceId from '@face-auth/face-id';

TypeScript

This syntax is used in environments that support ES6 modules, such as modern browsers and some build tools like Webpack or Babel. The import statement is used to import the FaceId class from the @face-auth/face-id package.

Initialize with credentials

Create an instance of the FaceId class with your domain and client token:

const faceId = new FaceId('<domain>', '<client_token>');

TypeScript

Replace <domain> and <client_token> with your actual credentials obtained from the face-auth platform.

First Use

After setting up and initializing the package, you can start performing basic operations. Follow these steps for initial interactions:

Making the First API Call

Use the provided functions to register a user or identify a face:

async function registerUser(userName, photo) {
    const imageType = 'image/png';
    photo.toBlob(async (imageBlob) => {    
        try {
            let result = await faceId.register(userName, imageBlob, imageType);
            console.log('User registered:', result);
        } catch (error) {
            console.error('Error registering user:', error);
        }
    }, imageType);
}

async function identifyFace(photo) {
    const imageType = 'image/png';
    photo.toBlob(async (imageBlob) => {    
        try {
            let result = await faceId.identifyFace(imageBlob, imageType);
            console.log('Face identified successfully:', result);
        } catch (error) {
            console.error('Error identifying user:', error);
        }
    }, imageType);
}

TypeScript

This guide helps users quickly get up and running with the @face-auth/face-id package, allowing them to perform basic operations and verify the setup.

How can we help?