📧 Gmail Integration
Melify uses the Gmail API to read and process emails securely. This guide will walk you through setting up Google OAuth 2.0 authentication to enable Gmail integration.
Prerequisites
- A Google account
- Access to Google Cloud Console
- Admin access to your project
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console
- Click on the project dropdown in the top navigation bar
- Click "New Project"
- Enter a project name (e.g., "melify-development")
- Click "Create"
Step 2: Enable the Gmail API
- In the Google Cloud Console, navigate to "APIs & Services" > "Library"
- Search for "Gmail API"
- Click on "Gmail API" in the results
- Click "Enable"
Step 3: Configure OAuth Consent Screen
- Navigate to "APIs & Services" > "OAuth consent screen"
- Select "External" if you want to allow any Google account, or "Internal" for organization-only access
- Click "Create"
- Fill in the required information:
- App name: Melify
- User support email: Your email address
- Developer contact information: Your email address
- Click "Save and Continue"
- On the "Scopes" page, click "Add or Remove Scopes"
- Add the following scopes:
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.modify
https://mail.google.com/
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/calendar.readonly
- Click "Update" and then "Save and Continue"
- Add your email in test users to be able to use it in Melify platform
- Review and click "Back to Dashboard"
Step 4: Create OAuth 2.0 Client ID
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Web application" as the application type
- Fill in the following:
- Name: Melify Web Client
- Authorized JavaScript origins:
http://localhost:3030
(for development)- Your production URL (when deploying)
- Authorized redirect URIs:
http://localhost:8080/api/auth/googleredirect
- Your production redirect URIs
- Click "Create"
Step 5: Retrieve Client ID and Secret
After creating the OAuth client, you'll see a dialog with your credentials:
- Client ID: Copy this value for
GOOGLE_CLIENT_ID
- Client Secret: Copy this value for
GOOGLE_CLIENT_SECRET
caution
Keep your Client Secret secure! Never commit it to version control or expose it publicly.
Step 6: Configure Environment Variables
Add the following environment variables to your configuration (We'll do the env setup on the next step):
Client
NEXT_PUBLIC_CLIENT_ID=<YOUR_CLIENT_ID>
API
GOOGLE_CLIENT_ID=<YOUR_CLIENT_ID>
GOOGLE_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
Root
GOOGLE_CLIENT_ID=<YOUR_CLIENT_ID>
GOOGLE_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
Troubleshooting
Common Issues
-
Invalid Client Error
- Verify that your Client ID and Secret are correctly copied
- Ensure redirect URIs match exactly (including http/https and trailing slashes)
-
Access Denied
- Check that all required scopes are added to the OAuth consent screen
- Verify the user has granted necessary permissions
-
Redirect URI Mismatch
- Double-check that all redirect URIs in Google Cloud Console match your application's configuration
- Remember to add both development and production URIs
Additional Resources
tip
For production deployments, consider using Google Cloud Secret Manager or similar services to manage your secrets securely.