Skip to content

NylasConnect.onConnectStateChange()

Use the onConnectStateChange method to subscribe to authentication state changes.

nylasConnect.onConnectStateChange((state) => {
console.log('Auth state changed:', state);
});

The state change callback receives comprehensive event information including the event type, session data, and optional event-specific data.

PropertyTypeDescription
dataConnectEventData[T]?An optional event-specific payload containing additional information about the event.
eventConnectEventThe event type.
sessionConnectResult | nullData about the current session. Returns null if no active session is available.
  • Authentication flow events
    • CONNECT_CALLBACK_RECEIVED: The callback URL was processed.
    • CONNECT_CANCELLED: The authentication flow was cancelled.
    • CONNECT_ERROR: The authentication flow failed.
    • CONNECT_POPUP_CLOSED: The pop-up authentication window closed.
    • CONNECT_POPUP_OPENED: The pop-up authentication window opened.
    • CONNECT_REDIRECT: The user was redirected to the OAuth provider.
    • CONNECT_STARTED: NylasConnect.connect() was called.
    • CONNECT_SUCCESS: The authentication flow completed successfully.
  • Session management events
    • SESSION_EXPIRED: A session expired.
    • SESSION_INVALID: A session became invalid.
    • SESSION_RESTORED: An existing session was found on initialization.
    • SIGNED_IN: A grant was authenticated successfully and connected to Nylas.
    • SIGNED_OUT: A grant was signed out from Nylas.
  • Token management events
    • TOKEN_REFRESH_ERROR: Token refresh failed.
    • TOKEN_REFRESHED: The access token was refreshed.
    • TOKEN_VALIDATION_ERROR: Token validation failed.
  • Grant and profile events
    • GRANT_PROFILE_LOADED: The grant profile was fetched.
    • GRANT_UPDATED: Information about the grant changed.
  • Connection and network events
    • CONNECTION_STATUS_CHANGED: The connection status changed.
    • NETWORK_ERROR: A network request failed.
  • Storage events
    • STORAGE_CLEARED: Authentication storage was cleared.
    • STORAGE_ERROR: A storage operation failed.