What are lifecycle events?
Lifecycle events let you customize Nango’s behavior at different points in a Connection’s lifecycle. When certain things happen for a Connection, Nango triggers an event. You can register an event handler Function for a specific event and integration. Example: You register apost-connection-creation event handler on your Salesforce integration. Nango will call this function once for each Salesforce connection, immediately after it has been created.
All lifecycle event executions are logged in Nango’s logs.
Supported lifecycle events
| Event | Description |
|---|---|
validate-connection | Occurs when a connection is being created. Allows custom validation of credentials. Rejects and deletes the connection if validation fails. |
post-connection-creation | Occurs immediately after a connection has been created. |
pre-connection-deletion | Occurs before a connection is deleted. |
Common use cases
- Credential validation: Integration-specific validation logic for API keys (e.g., check permissions to access a specific endpoint)
- Webhook registration: Register webhook subscriptions after a connection has been created
- Account configuration: Fetch account configuration information from the external API
- Cleanup on deletion: Deregister webhook subscriptions or revoke access tokens when a connection is deleted
How to implement an event handler
Step 1 - Initial Functions setup
If you don’t have anango-integrations folder yet, follow the initial Functions setup guide first.
Step 2 - Create your event function file
Create a new file in your integration’son-events folder:
The integration folder name (e.g.,
salesforce) must match an integration ID in your Nango dashboard.setup.ts
index.ts file:
index.ts
Step 3 - Implement the event function
Implement your handler logic in theexec function. The function kicks off when the associated event occurs.
Helpful resources:
nangoobject reference for SDK methods available in event functions- Reference implementations repo for examples (search for
onEvent() - Leveraging AI agents guide to build with Claude Code, Cursor & other AI agents