Installation
Types
GmailConnection
Represents a Gmail OAuth connection.Unique identifier for the connection
The connected Gmail email address
ISO 8601 timestamp when the connection was established
ISO 8601 timestamp when the OAuth token expires
Whether the connection is currently active
Current status of the connection
GmailStatus
Aggregated status information for all Gmail connections.Array of all Gmail connections
Total number of connections
Number of active connections (connected + needs_reconnect)
Number of fully connected accounts
Number of accounts that need reconnection
Number of disconnected accounts
GmailWatch
Represents a Gmail API watch for push notifications.Unique identifier for the watch
Email address being watched
Gmail API watch identifier
Pub/Sub topic name for notifications
ISO 8601 timestamp when the watch expires
Whether the watch is currently active
Methods
getConnectionStatus
Retrieves the Gmail connection status for a user with caching.The user ID to fetch connection status for
The aggregated Gmail connection status
Results are cached for 60 seconds to reduce database queries. Use
clearConnectionStatusCache() to invalidate the cache when making connection changes.Example
getWatches
Retrieves active Gmail watches for a user.The user ID to fetch watches for
Array of active Gmail watches, empty array if none found or on error
Example
connectGmail
Initiates the Gmail OAuth connection flow by redirecting to the authentication endpoint.This method redirects the user to the OAuth flow and does not return. It requires an active Supabase session.
- Error if no active session exists
- Error if user cannot be retrieved
Example
disconnectGmail
Disconnects a Gmail account by revoking the OAuth token.The ID of the Gmail connection to disconnect
Whether the disconnection was successful
Error message if the disconnection failed
Example
clearConnectionStatusCache
Clears the cached Gmail connection status.Optional user ID. If provided, clears cache only for that user. If omitted, clears all cached statuses.
Example
Error Handling
All async methods may throw errors. It’s recommended to wrap calls in try-catch blocks:Dependencies
- Supabase Client: Uses
getSupabase()for database queries and authentication - Edge Functions: Calls the following Supabase Edge Functions:
auth-start: Initiates OAuth flowgmail-disconnect: Revokes OAuth tokens
- Database Tables:
user_oauth_tokens: Stores OAuth connection datagmail_watches: Stores Gmail watch configurations