Gating access to features

Overview

In this quick start guide we'll demonstrate how to gate access to features.

The functionality that’s included in each plan is defined by a combination of features and their configuration, referred to in Stigg as entitlements.

Before we begin

In order to complete this guide in your application code, please make sure that you have:


Initializing the client SDK

The first step is to initialize Stigg's client SDK with the client API key of the environment that's integrated with Stigg, and the ID of the relevant customer.

The customer ID can usually be retrieved after a customer signs-in or restores their session.

import Stigg from '@stigg/js-client-sdk';

const stiggClient = await Stigg.initialize({ 
    apiKey: '<CLIENT-API-KEY>',
    customerId: "<CUSTOMER-ID>"
});

export default stiggClient; 

Checking whether the customer can access the feature

Checking whether the customer has access to the feature, is achieved in 2 steps:

  1. Query the customer's entitlement by passing the feature ID:

    const entitlement = stiggClient.getMeteredEntitlement({
      featureId: "feature-sso"
    });
    
    
  2. Use the result to determine whether they have access to the feature:

    if (entitlement.hasAccess) {
      console.log("Customer has access to the SSO feature");
    }}
    

Additional resources


What’s Next