Skip to main content
Version: 2.0.0

Web JavaScript

Initial Setup

The LoginID Web SDK provides a set of functions and components that can be integrated into your web (browser) application. To use it, you'll need to configure the SDK with your LoginID credentials and then call the appropriate methods for signup and signin functionalities.

This SDK facilitates a smooth integration process, eliminating the need to redirect users to external pages outside of your application.

Required settings:

  • Base URL
  • Application ID

Add SDK to Existing Application

npm install --save @loginid/web-sdk

Create an SDK Instance

NPM
import { LoginIDWebSDK } from "@loginid/web-sdk";

// Obtain credentials from LoginID Tenant
const BASE_URL = process.env.BASE_URL;
const APP_ID = process.env.APP_ID;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
appId: APP_ID,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);

API Reference

LoginIDWebSDK Class

Effortlessly integrate passkey-based sign-in and sign-up functionalities along with passkey management into your front-end application using this class.

Constructor

Initializes a new instance of LoginIDWebSDK with the provided configuration.

constructor(config: LoginIDConfig);

Parameter Type Details

ParameterTypeRequiredDetails
configLoginIDConfigyesThe Login SDK configuration object.
config.baseUrlLoginIDConfigyesThe base URL of LoginID service.
config.appIdLoginIDConfigyesThe application ID of your LoginID application.

registerWithPasskey

Signs up with a passkey for the given username.

async registerWithPasskey(
username: string,
options?: RegisterWithPasskeysOptions
): Promise<PasskeyResult>;
ParameterTypeRequiredDetails
usernameStringtrueThe username for the sign-up
optionsRegisterWithPasskeysOptionsfalseAdditional options for the sign-up process.
options.displayNamestringfalseA human-palatable name for the user account, intended only for display on your passkeys and modals.

authenticateWithPasskey

Signs in with a passkey for the given username.

async authenticateWithPasskey(
username: string,
options?: AuthenticateWithPasskeysOptions
): Promise<PasskeyResult>;
ParameterTypeRequiredDetails
usernameStringfalseThe username for the sign-in.
optionsAuthenticateWithPasskeysOptionsfalseAdditional options for the sign-up process.
options.autoFillbooleanfalseWhen true will enable passkeys in the browser autofill suggestions if supported (conditional UI). username does not need to be set.
options.abortSignalAbortSignalfalseThis should be used with the options.autoFill option to trigger the cancellation of the passkey conditional UI. Pass this if additional passkeys API calls may be anticipated on the current context page.

Utility Functions

Helpful utility functions that will aid with passkey integration.

doesDeviceSupportPasskeys

This asynchronous function checks if the current device supports passkeys, based on the availability of platform authenticators like Touch ID, Face ID, Windows Hello, or other device unlock features. It provides specific solutions if passkeys are not supported, guiding users towards enabling the necessary features or updating their browsers.

isPlatformAuthenticatorAvailable

Checks if the user's device has a platform authenticator available that supports user verification. It is useful for determining if the device can participate in biometric-based or device PIN-based authentication flows. doesDeviceSupportPasskeys also uses this function to determine a result.

isConditionalUIAvailable

Checks if the current browser supports autofill for passkeys.