@nangohq/frontend.
Installation
- npm
- yarn
- pnpm
Constructor
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.Your environment public key from the Nango dashboard. This is not sensitive, but it gives access to all integrations. Prefer
connectSessionToken for production.The Nango instance URL. Defaults to
https://api.nango.dev. Use http://localhost:3003 for local development or your self-hosted instance URL.Custom WebSocket path for self-hosted instances. Defaults to
/.Width of the OAuth popup window in pixels.
Height of the OAuth popup window in pixels.
When
true, prints additional console logs to help debug authorization issues.Connect UI
The recommended way to integrate Nango in your frontend.openConnectUI renders a full-screen iframe that guides users through connecting their accounts.
The connect session token. Can be set asynchronously via
connectUI.setSessionToken(token) after the UI is opened.Callback fired on UI events. See event types below.
The URL to load the Connect UI from. Defaults to
https://connect.nango.dev.The Nango API URL to use inside the Connect UI. Defaults to
https://api.nango.dev.When
true, a closed OAuth popup is treated as a failed authorization. Defaults to false.Language code for the Connect UI (e.g.
en, fr). Defaults to the browser language.Override the UI theme, independent of your dashboard setting.
ConnectUI instance with the following methods:
connectUI.setSessionToken(token)— update the session token asynchronouslyconnectUI.close()— programmatically close the Connect UI
Connect UI events
| Event type | Payload | Description |
|---|---|---|
ready | — | The iframe has loaded and is ready to receive the session token. |
connect | { connectionId, providerConfigKey } | A connection was successfully created. |
close | — | The user closed the Connect UI. |
error | { errorType, errorMessage } | An error occurred during the flow. |
settings_changed | ConnectUISettings | The user changed a UI setting (e.g. theme). |
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.
- OAuth
- API key
- Basic auth
Opens a popup window for the OAuth flow.
The integration ID as configured in the Nango dashboard.
An optional ID for this connection. If omitted, Nango generates one.
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.When
true, closing the OAuth popup before completion is treated as a failed auth.Additional query parameters to append to the OAuth authorization URL.
User-specific OAuth scopes (Slack only).
The integration ID.
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 anAuthError instance with a type and message.
| Type | Description |
|---|---|
missing_auth_token | Neither a public key nor a session token was provided. |
blocked_by_browser | The OAuth popup was blocked by the browser. |
invalid_host_url | The provided host URL is invalid. |
missing_credentials | Required credentials were not provided. |
window_closed | The OAuth window was closed before the flow completed. |
connection_test_failed | Credential validation failed before the connection was established. |
missing_connect_session_token | Reconnect was called without a session token. |
resource_capped | The connection limit for your plan has been reached. |
unknown_error | An unexpected error occurred. |