The NylasConnectButton is a prebuilt React component that triggers the Nylas Connect authentication flow. It supports both pop-up and redirect methods, includes sensible loading/disabled states, and offers styling options out of the box.
import { NylasConnectButton } from "@nylas/react/connect" ;
export default function ConnectCTA () {
clientId = {process.env. NYLAS_CLIENT_ID ! }
redirectUri = {process.env. NYLAS_REDIRECT_URI ! }
The component renders as <button type="button">. When a connection is in progress, the button is disabled and sets aria-busy for accessibility purposes.
We recommend using the NylasConnectButton component when you want a drag-and-drop authentication experience with minimal setup. If you need custom UI or UX, or more granular control over state, use the useNylasConnect hook instead.
The NylasConnectButton automatically handles OAuth callbacks when the component is mounted. However, if you render the button conditionally (for example, only when the user is not authenticated), the button won’t be present on the callback page to handle the OAuth response.
If you conditionally render the button, you must handle the callback yourself using the useNylasConnect hook .
The button is always rendered, so it can handle the callback automatically:
import { NylasConnectButton } from "@nylas/react/connect" ;
clientId = {process.env. NYLAS_CLIENT_ID ! }
redirectUri = {process.env. NYLAS_REDIRECT_URI ! }
console. log ( "Connected:" , result.grantInfo?.email);
The button won’t be mounted on the callback page, so the OAuth response won’t be processed:
import { NylasConnectButton } from "@nylas/react/connect" ;
const [ isAuthenticated , setIsAuthenticated ] = useState ( false );
// ❌ Button won't be present after redirect, callback won't be handled
clientId = {process.env. NYLAS_CLIENT_ID ! }
redirectUri = {process.env. NYLAS_REDIRECT_URI ! }
Use the hook to handle callbacks manually when rendering conditionally:
import { useNylasConnect } from "@nylas/react/connect" ;
const { isConnected , grant , connect , isLoading } = useNylasConnect ({
clientId: process.env. NYLAS_CLIENT_ID ! ,
redirectUri: process.env. NYLAS_REDIRECT_URI ! ,
autoHandleCallback: true , // Hook handles callback automatically
return < div >Loading...</ div >;
if (isConnected && grant) {
< h2 >Welcome, {grant.email}!</ h2 >
< p >Provider: {grant.provider}</ p >
// Now it's safe to conditionally render the button
await connect ({ method: "inline" });
console. error ( "Connection failed:" , error);
Name apiUrlDescription The Nylas API base URL. Type https://api.us.nylas.com | https://api.eu.nylas.comDefault https://api.us.nylas.com
Name childrenDescription Custom button content. Overrides text . Type ReactNode?
Name classNameDescription Additional class names to add to the NylasConnectButton element. Type string?
Name clientIdDescription Your Nylas application’s client ID. Type string
Name codeExchangeDescription A custom backend code exchange. This replaces the built-in token exchange. Type CodeExchangeMethod?
Name cssVarsDescription A set of custom CSS properties (for example, --nylas-btn-bg, --nylas-btn-fg, and so on). Type Record<string, string>?
Name defaultScopesDescription Default scopes to configure for the NylasConnect instance. These scopes are used when scopes is not provided. This is a configuration option that sets defaults for the client. Type NylasScope[]?
Name disabledDescription When true, disables the NylasConnectButton. Type boolean?
Name identityProviderTokenDescription A callback that returns an external identity provider JWT. This is set to idp_claims during token exchange. Type () => Promise<string | null> | string | null
Name loginHintDescription An email address to pre-fill on the provider authentication page. Type string?
Name methodDescription Specify the authentication method. When inline, redirects the user to the provider using the URL returned from connect(). When popup, opens a pop-up window and resolves with ConnectResult on success. Type popup | inlineDefault inline
Name persistTokensDescription When true, Nylas Connect stores tokens in localStorage. When false, tokens are stored in memory only. Type boolean?Default true
Name popupHeightDescription The height of the authentication pop-up, in pixels. Used when method is popup. Type number? Default 600
Name popupWidthDescription The width of the authentication pop-up, in pixels. Used when method is popup. Type number? Default 500
Name providerDescription The OAuth provider that Nylas Connect will use to authenticate users. Type Provider?
Name redirectUriDescription The OAuth redirect URI that matches your application configuration. Type string?
Name scopesDescription Scopes to request for this specific authentication attempt. This is an option property that overrides defaultScopes when provided. Use this to request different scopes for individual connection attempts. Type NylasScope[]?
Name sizeDescription The size of the NylasConnectButton when using one of the default styles. Type sm | md | lgDefault md
Name styleDescription Inline styles for the NylasConnectButton. Type CSSProperties?
Name textDescription Text to be displayed as the NylasConnectButton label. Ignored when children is specified. Type string? Default ”Connect your inbox”
Name unstyledDescription When true, disables the default NylasConnectButton style classes. Type boolean? Default false
Name variantDescription The visual variant for the default NylasConnectButton styles. Type primary | outlineDefault primary
Event Type Description onCancel(reason: string) => void?Called when the user cancels the authentication flow or closes the pop-up. onError(error: Error) => void?Called when an error occurs during authentication. onStart() => void?Called when the user clicks the button and the authentication flow begins. onSuccess(result: ConnectResult) => void?Called when the pop-up authentication flow completes and the provider returns tokens for the user.
Pop-up method Inline method Callback events Custom styling Backend code exchange
"https://www.googleapis.com/auth/gmail.readonly" ,
< NylasConnectButton clientId = "..." redirectUri = "..." method = "inline" />
onStart = {() => console. log ( "starting" )}
onSuccess = {( res ) => console. log ( "success" , res)}
onCancel = {( reason ) => console. log ( "cancel" , reason)}
onError = {( e ) => console. error ( "error" , e)}
cssVars = {{ "--nylas-btn-bg" : "#111" , "--nylas-btn-fg" : "#fff" }}
// Advanced: backend code exchange and external identity provider token
codeExchange = { async ( params ) => {
const res = await fetch ( "/api/auth/exchange" , {
headers: { "Content-Type" : "application/json" },
body: JSON . stringify (params),
if ( ! res.ok) throw new Error ( "Token exchange failed" );
identityProviderToken = { async () => {
// Return a JWT string from your identity provider, or null