A minimal React SPA demonstrating the power and simplicity of the @nylas/connect
SDK.
- π One-line SDK setup
- π Secure popup authentication flow
- π‘ Event-driven state management
- β¨ Automatic callback handling
- π§ Instant access to grant information
- π¨ Beautiful dark mode UI with Tailwind CSS
- Node.js (v18 or higher recommended)
- A Nylas account and Client ID (Sign up here)
- Important: You must configure a callback redirect URI in your Nylas Dashboard before the authentication flow will work
npm install
This step is required before authentication will work.
- Go to your Nylas Dashboard
- Navigate to your application settings
- Add a callback URI that matches your local development URL
For local development, add:
http://localhost:8080
Or if the port is different (check your terminal output):
http://localhost:5174
Note: The callback URI must match your application's origin exactly. You can add multiple URIs for different environments (development, staging, production).
Copy env.example
to .env
and add your Nylas Client ID:
cp env.example .env
Then edit .env
:
VITE_NYLAS_CLIENT_ID=your_actual_client_id_here
Get your Client ID from the Nylas Dashboard
npm run dev
Navigate to the URL shown in the terminal (typically http://localhost:8080
or http://localhost:5174
)
This demo showcases the simplicity of @nylas/connect
:
const nylas = new NylasConnect({
clientId: "YOUR_CLIENT_ID",
redirectUri: window.location.origin,
});
const unsubscribe = nylas.onConnectStateChange((event, session) => {
if (event === 'CONNECT_SUCCESS' && session) {
console.log('Connected:', session.grantInfo?.email);
} else if (event === 'SESSION_RESTORED' && session) {
console.log('Session restored');
} else if (event === 'SIGNED_OUT') {
console.log('User signed out');
}
});
// Handle OAuth callback
nylas.callback();
Available Events:
- Authentication:
CONNECT_SUCCESS
,CONNECT_ERROR
,CONNECT_CANCELLED
,CONNECT_STARTED
- Session:
SESSION_RESTORED
,SESSION_EXPIRED
,SIGNED_IN
,SIGNED_OUT
- Token:
TOKEN_REFRESHED
,TOKEN_REFRESH_ERROR
- Popup:
CONNECT_POPUP_OPENED
,CONNECT_POPUP_CLOSED
- And more!
π See
EVENTS.md
for complete event reference with examples
// Open authentication popup - events handle state updates
await nylas.connect({ method: 'popup' });
The SDK emits events for all state changes, making integration clean and reactive!
βββ src/
β βββ App.tsx # Main application component
β βββ main.tsx # Application entry point
β βββ index.css # Tailwind CSS imports
βββ env.example # Environment variable template
βββ package.json # Dependencies and scripts
- Initial View: A clean interface with a "Connect Your Account" button
- Authentication: Click the button to open a secure popup for account connection
- Success View: After successful connection, see:
- User's full name
- Email address
- Grant ID
- Disconnect button
π‘ The SDK automatically manages session persistence across page refreshes!
- React - UI framework
- TypeScript - Type safety
- Vite - Build tool
- Tailwind CSS - Styling
- @nylas/connect - Email connectivity SDK
Most common issue: The callback URI in your Nylas Dashboard doesn't match your application's URL.
Make sure:
- The callback URI is configured in your Nylas Dashboard
- The URI matches exactly (including protocol and port):
http://localhost:8080
orhttp://localhost:5174
- You've restarted the dev server after adding the callback URI
- Your
VITE_NYLAS_CLIENT_ID
environment variable is set correctly
If Vite uses a different port (e.g., 5174 instead of 8080), make sure to add that exact port to your callback URIs in the Nylas Dashboard.
MIT
Built with β€οΈ using Nylas Connect