Frontend SDK
Frontend

The Nango frontend SDK is available on NPM with the package @nangohq/frontend.

Initiating Nango

  • Nango Cloud

  • Localhost

  • Self-hosted

Get your Public Key from the Project Settings page.

import Nango from '@nangohq/frontend';

let nango = new Nango({ publicKey: '<PUBLIC-KEY>' });

Triggering OAuth flows

You trigger OAuth flows with nango.auth. This function returns a promise, which resolves if the OAuth flow was successful, and rejects if there was an error.

nango
    .auth('<INTEGRATION-ID>', '<CONNECTION-ID>')
    .then((result) => {
        // result is an object with:
        // {
        //      providerConfigKey: '<INTEGRATION-ID>',
        //      connectionId: '<CONNECTION-ID>
        // }
    })
    .catch((error) => {
        // Error is an object with:
        // {
        //    error: {
        //      type: 'authorization_cancelled', (or similar)
        //      message: 'Authorization fail: The user has closed the authorization modal before the process was complete.'  (or similar)
        //    }
        // }
    });

OAuth flows requiring extra configuration

Some API Providers require some connection-specific configuration (e.g. Zendesk, Shopify).

For example, Zendesk has the following authorization URL, where the subdomain is specific to a user’s Zendesk account:

https://<USER-SUBDOMAIN>.zendesk.com/oauth/authorizations/new

To set the subdomain pass in an additional configuration object to nango.auth():

nango.auth('zendesk', '<CONNECTION-ID>', {
    params: { subdomain: '<ZENDESK-SUBDOMAIN>' }
});