SDK

Connections

Check whether a user has connected a provider, list all connections, or get the OAuth URL to prompt users to connect.

isConnected

Check if a specific provider is connected and active for the current user.

TypeScript
const hasGmail = await integrations.isConnected('gmail')
const hasCalendar = await integrations.isConnected('google_calendar')
const hasDrive = await integrations.isConnected('google_drive')
if (!hasGmail) {
// Prompt user to connect Gmail
const url = integrations.getConnectUrl('gmail')
// redirect or show link...
}

getConnections

Retrieve the connection status for all providers at once. Each connection includes a providerId and a status field.

Connection statuses

  • active -- The provider is connected and tokens are valid.
  • expired -- The OAuth token has expired. Prompt the user to re-authorize.
TypeScript
const connections = await integrations.getConnections()
// => [
// { providerId: 'gmail', status: 'active' },
// { providerId: 'google_calendar', status: 'active' },
// { providerId: 'google_drive', status: 'expired' },
// ]

getConnectUrl

Generate the OAuth URL that kicks off the connection flow for a provider. Optionally pass a return URL to redirect back to your app after authorization.

TypeScript
// Basic connect URL
const url = integrations.getConnectUrl('gmail')
// => "https://leash.build/api/integrations/connect/gmail"
// With return URL
const url = integrations.getConnectUrl('gmail', 'https://my-app.un.leash.build/settings')
// => "https://leash.build/api/integrations/connect/gmail?return_url=https%3A%2F%2F..."