Javascript

Portabl Javascript SDK

The Portabl JavaScript SDK makes it easy to verify users in your application.

⚠️

This guide assumes that all prerequisite steps mentioned in the Verify Users have been applied and configured.

Installation

sh copy npm install --save @portabl/js-connect-with-portabl

Create the client

Initialize the client with an organizationId and the respective domains for the environment.

const connectClient = new ConnectClient({
  organizationId: '<PORTABL_ORGANIZATION_ID>',
  projectId: '<PORTABL_PROJECT_ID>',
  connectDomain: 'https://api.getportabl.com',
  passportDomain: 'https://my.getportabl.com',
});

Initialize Verification

To begin a verification, we can trigger authorizeWithRedirect. This will initialize the OIDC flow and redirect the user to the Portabl Passport, where they will go through and verify any details your verification dataprofile requires.

document.getElementById('verify').addEventListener('click', async () => {
  await connectClient.authorizeWithRedirect();
});

Handle the redirect

Once the user has completed the verification flow, they will be redirected to the Redirect URI configured inside of your Project's Verify settings. Here you will need to trigger handleRedirectCallback which will fetch the VP_Token and ID_Token associated to your verification.

window.addEventListener('load', async () => {
  await connectClient.handleRedirectCallback();
});

Check if the user is verified

To check if the user has succesfully been verified, use the getIsAuthorized method.

const isUserAuthenticated = await connectClient.getIsAuthorized();

Reset Verification Status

To reset a user's verification status you can invoke resetAuthorization

connectClient.resetAuthorization();

Options

OptionTypeDefaultDescription
organizationIdstringThe unique identifier of your organization
projectIdstringThe unique identifier of your project
connectDomainstringThe domain for accessing the Connect API
passportDomainstringThe domain of the Portabl passport