Skip to content

NylasConnect class overview

The NylasConnect class is the core of the Nylas Connect library. It provides methods for OAuth authentication, token management, and grant creation and management.

import { NylasConnect } from "@nylas/connect";
const nylasConnect = new NylasConnect({
clientId: process.env.NYLAS_CLIENT_ID!,
redirectUri: process.env.NYLAS_REDIRECT_URI!,
apiUrl: process.env.NYLAS_API_URL || "https://api.us.nylas.com",
environment: "production",
persistTokens: true,
debug: false,
logLevel: "error",
});
// Set up authentication state monitoring
nylasConnect.onConnectStateChange((state) => {
console.log("Auth state changed:", state);
switch (state.type) {
case "connected":
// Handle successful connection
break;
case "disconnected":
// Handle disconnection
break;
case "error":
// Handle authentication errors
console.error("Auth error:", state.error);
break;
}
});

The NylasConnect constructor accepts a ConnectConfig object with the following options.

Property
Toggle details

The NylasConnect class includes the following methods. Click on any method name to view its detailed documentation.

ConnectError extends the standard Error interface and adds fields for better error handling.

PropertyTypeDescription
codestringAn error code for programmatic error handling.
descriptionstring?A human-readable description of the error.
docsUrlstring?A link to relevant documentation.
fixstring?A suggested solution for resolving the error.
originalErrorError?The original error, if the ConnectError wraps another error.
NameEnvironment
DescriptionYour project’s deployment environment.
Enumdevelopment | staging | production

Default scope settings for different providers.