Skip to main content
Trigger authorization flows in your frontend with this SDK. It is available on NPM as @nangohq/frontend.

Instantiate the frontend SDK

Parameters

Connect using Nango Connect UI

Nango provides a UI component that guides your app’s users through automatically and securely setting up an integration. This UI is hosted on Nango’s servers and requires minimal setup on your end to get started quickly. This is the recommended way to use Nango in your frontend.
Parameters Response

Connect using the headless client

You store end-user credentials with the nango.auth method. It creates a connection in Nango. For OAuth and the other popup-based modes (GitHub App, GitHub App OAuth, MCP OAuth and plugin installs), nango.auth opens a popup. For credential-based modes, pass the credentials you collected and the connection is created directly, with no popup. Field names for the two-step and JWT modes are the credentials fields of the integration’s provider in providers.yaml.
The frontend SDK runs in your user’s browser, so only pass credentials your end user entered. Never hard-code your own app’s secrets, such as client secrets, private keys or developer keys, in frontend code. To create a connection with credentials you hold on your server, use the import connection API from your backend.
For OAuth (OAuth 2, OAuth 1, GitHub App, GitHub App OAuth, MCP OAuth and plugin installs such as Crisp), this will open a modal to let the user log in to their external account.
Parameters Success response Error response nango.auth rejects with an AuthError:

Reconnect an existing connection

To re-authorize an existing connection, for example after its credentials expired or were revoked, create a reconnect session token with the reconnect session API and call nango.reconnect. It takes the integration ID and the same options as nango.auth, and keeps the connection ID.
nango.reconnect throws missing_connect_session_token if the SDK was instantiated without a connect session token.

Error Handling

The Nango Frontend SDK may throw different types of errors during authentication and connection setup. Below are the error types the SDK defines. For headless flows, type can also be any error code returned by the Nango API (e.g. unknown_provider_config).
  1. missing_auth_token
    • Occurs when neither a public key nor a connect session token is provided.
    • Message: “You must specify a public key OR a connect session token (cf. documentation).”
  2. blocked_by_browser
    • Occurs when the browser blocks the popup window for authentication.
    • Message: “Modal blocked by browser”
  3. invalid_host_url
    • Occurs when the provided host URL is invalid.
    • Message: “Invalid URL provided for the Nango host.”
  4. missing_credentials
    • Occurs when required credentials are not provided, including installation: 'outbound' without a credentials object.
    • Message: “You must specify credentials.” or “Credentials are required for custom auth”
  5. window_closed
    • Occurs when the authentication window is closed before completing the flow.
    • Message: “The authorization window was closed before the authorization flow was completed”
  6. connection_test_failed
    • Occurs when credential verification fails for certain integrations before the connection is established.
    • Message: “The given credentials were found to be invalid. Please check the credentials and try again.”
  7. connection_validation_failed
  8. missing_connect_session_token
    • Occurs when attempting to reconnect without a session token.
    • Message: “Reconnect requires a session token”
  9. resource_capped
    • Occurs when the resource usage limit has been reached.
    • Message: “Reached maximum number of allowed connections. Upgrade your plan to get rid of connection limits.”
  10. unknown_error
    • Occurs when an unexpected error happens that doesn’t fall into other error categories.
    • Message: Varies depending on the underlying error (e.g., network failures, unexpected exceptions)

Error Response Structure

Errors returned by the Nango API follow this structure. The SDK turns code into the AuthError’s type, and message into its message:

Handling Errors

You can handle these errors in your code using the AuthError class.
Questions, problems, feedback? Please reach out in the Slack community.