Overview
Initiates the Google OAuth 2.0 authentication flow to grant Money Tracker access to read Gmail messages. This is the first step in connecting a Gmail account.Endpoint
Authentication
Requires a valid Supabase user token passed as a query parameter.Request
Query Parameters
Supabase JWT authentication token for the authenticated user. This token is passed as state to the OAuth flow to maintain session continuity.
Example Request
Response
This endpoint performs a 302 redirect to Google’s OAuth consent page.Redirect Parameters
The redirect URL includes the following OAuth 2.0 parameters:Google OAuth client ID configured in environment variables
Callback URL that Google will redirect to after authorization (points to
auth-callback function)Set to
code for authorization code flowRequested OAuth scopes:
https://www.googleapis.com/auth/gmail.readonly- Read Gmail messageshttps://www.googleapis.com/auth/userinfo.email- Access user’s email address
Contains the Supabase token passed in the request to maintain session state
Set to
offline to request a refresh tokenSet to
consent to force the consent screen and ensure a refresh token is issuedError Responses
401 Unauthorized
Returned when the authentication token is missing.405 Method Not Allowed
Returned when using any HTTP method other than GET.500 Internal Server Error
Returned when OAuth configuration is missing or an internal error occurs.Implementation Details
Environment Variables Required
GOOGLE_CLIENT_ID- Google OAuth client IDOAUTH_REDIRECT_URI- OAuth callback URL (defaults to local development URL)
OAuth Flow
- Validates user authentication token
- Retrieves Google OAuth configuration from environment
- Constructs authorization URL with required scopes
- Redirects user to Google consent screen
- User grants permissions
- Google redirects to
auth-callbackwith authorization code
Security Notes
- The Supabase token is passed as the OAuth
stateparameter to prevent CSRF attacks - Access type is set to
offlineto obtain a refresh token for long-term access - Prompt is set to
consentto ensure refresh token issuance
Related Functions
- auth-callback - Handles the OAuth callback and stores tokens
- gmail-webhook - Processes Gmail notifications after authentication