Skip to main content
Nango handles OAuth for 250+ APIs, storing and automatically refreshing access tokens on your behalf. This makes it a natural fit for Trigger.dev tasks that need to call third-party APIs on behalf of your users. In this guide you’ll build a task that:
  1. Receives a Nango connectionId from your frontend
  2. Fetches a fresh GitHub access token from Nango inside the task
  3. Calls the GitHub API to retrieve the user’s open pull requests
  4. Uses Claude to summarize what’s being worked on
This pattern works for any API Nango supports. Swap GitHub for HubSpot, Slack, Notion, or any other provider.

Prerequisites

How it works

Step 1: Connect GitHub in Nango

1

Create a GitHub integration in Nango

  1. In your Nango dashboard, go to Integrations and click Set up new integration.
  2. Search for GitHub and select GitHub (User OAuth).
  3. Create and add a test connection
2

Add the Nango frontend SDK

Install the Nango frontend SDK in your Next.js project:
The frontend SDK requires a short-lived connect session token issued by your backend. Add an API route that creates the session:
app/api/nango-session/route.ts
Then add a connect button to your UI that fetches the token and opens the Nango OAuth flow:
app/page.tsx

Step 2: Create the Trigger.dev task

Install the required packages:
Create the task:

Step 3: Create the API route

Add a route handler that receives the connectionId from your frontend and triggers the task:
app/api/analyze-prs/route.ts

Step 4: Set environment variables

Add the following to your .env.local file:
Add NANGO_SECRET_KEY and ANTHROPIC_API_KEY as environment variables in your Trigger.dev project too. These are used inside the task at runtime.

Test it

1

Start your dev servers

2

Connect GitHub and trigger the task

Open your app, click Analyze my PRs, and complete the GitHub OAuth flow. The task will be triggered automatically.
3

Watch the run in Trigger.dev

Open your Trigger.dev dashboard and navigate to Runs to see the task execute. You’ll see the PR count and Claude’s summary in the output.
Your task is now fetching a fresh GitHub token from Nango, calling the GitHub API on behalf of the user, and using Claude to summarize their open PRs. No token storage or refresh logic required.

Next steps

  • Reuse the connectionId: Once a user has connected, store their connectionId and pass it in future task payloads. No need to re-authenticate.
  • Add retries: If the GitHub API returns a transient error, Trigger.dev retries will handle it automatically.
  • Switch providers: The same pattern works for any Nango-supported API. Change "github" to "hubspot", "slack", "notion", or any other provider.
  • Stream the analysis: Use Trigger.dev Realtime to stream Claude’s response back to your frontend as it’s generated.