Skip to main content
The frontend SDK lets you authenticate users with third-party APIs directly from your browser code. It is available on npm as @nangohq/frontend.

Installation


Constructor

string
A short-lived session token created server-side via nango.createConnectSession(). This is the recommended approach — it scopes the session to a specific end user and limits which integrations they can connect.
string
Your environment public key from the Nango dashboard. This is not sensitive, but it gives access to all integrations. Prefer connectSessionToken for production.
string
The Nango instance URL. Defaults to https://api.nango.dev. Use http://localhost:3003 for local development or your self-hosted instance URL.
string
Custom WebSocket path for self-hosted instances. Defaults to /.
number
Width of the OAuth popup window in pixels.
number
Height of the OAuth popup window in pixels.
boolean
When true, prints additional console logs to help debug authorization issues.
Find your public key in Settings > Environment Settings in the Nango dashboard.

Connect UI

The recommended way to integrate Nango in your frontend. openConnectUI renders a full-screen iframe that guides users through connecting their accounts.
string
The connect session token. Can be set asynchronously via connectUI.setSessionToken(token) after the UI is opened.
(event: ConnectUIEvent) => void
Callback fired on UI events. See event types below.
string
The URL to load the Connect UI from. Defaults to https://connect.nango.dev.
string
The Nango API URL to use inside the Connect UI. Defaults to https://api.nango.dev.
boolean
When true, a closed OAuth popup is treated as a failed authorization. Defaults to false.
string
Language code for the Connect UI (e.g. en, fr). Defaults to the browser language.
'light' | 'dark' | 'system'
Override the UI theme, independent of your dashboard setting.
Returns A ConnectUI instance with the following methods:
  • connectUI.setSessionToken(token) — update the session token asynchronously
  • connectUI.close() — programmatically close the Connect UI

Connect UI events


React integration


Headless auth (nango.auth)

For custom auth flows without the Connect UI, use nango.auth directly. This opens an OAuth popup or submits credentials to Nango.
Opens a popup window for the OAuth flow.
Parameters
string
required
The integration ID as configured in the Nango dashboard.
string
An optional ID for this connection. If omitted, Nango generates one.
object
Credentials to submit for non-OAuth integrations. Accepts apiKey, username/password, oauth_client_id_override/oauth_client_secret_override, and others depending on the provider.
boolean
When true, closing the OAuth popup before completion is treated as a failed auth.
Record<string, string>
Additional query parameters to append to the OAuth authorization URL.
string[]
User-specific OAuth scopes (Slack only).
Success response
string
The integration ID.
string
The ID of the newly created connection.

Reconnect

Re-authorizes an existing connection. Requires a connect session token.

Plain JavaScript integration


Error handling

All auth errors throw an AuthError instance with a type and message.
Error types