5.0 KiB
5.0 KiB
Google OAuth Setup Guide
This guide explains how to set up Google OAuth for Let's Event to enable Google Calendar integration and Google Meet link generation.
Overview
Let's Event integrates with Google Calendar to:
- Automatically create calendar events when someone books with you
- Generate Google Meet links for video conferencing
- Send calendar invites to attendees
- Keep your calendar synchronized with bookings
Prerequisites
- A Google Cloud Platform account
- Access to Google Cloud Console
Setup Steps
1. Create OAuth Credentials in Google Cloud Console
-
Go to Google Cloud Console
-
Create a new project or select an existing one
-
Enable the Google Calendar API:
- Go to "APIs & Services" > "Library"
- Search for "Google Calendar API"
- Click "Enable"
-
Configure OAuth consent screen:
- Go to "APIs & Services" > "OAuth consent screen"
- Choose "External" user type
- Fill in the required information:
- App name: Let's Event
- User support email: your email
- Developer contact: your email
- Add scopes:
openidhttps://www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/userinfo.profilehttps://www.googleapis.com/auth/calendar.events
- Save and continue
-
Create OAuth 2.0 Client ID:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Application type: "Web application"
- Add authorized redirect URIs:
- Development:
http://localhost:3000/api/auth/callback/google - Production:
https://your-domain.com/api/auth/callback/google
- Development:
- Click "Create"
- Copy the Client ID and Client Secret
2. Configure Environment Variables
Add the following to your .env file:
GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-client-secret"
3. Connect Your Google Account
- Start the development server:
npm run dev - Navigate to Settings page in the dashboard
- Click "Connect Google Calendar"
- Authorize the application to access your Google Calendar
- You'll be redirected back to the Settings page
How It Works
Authentication Flow
- User clicks "Connect Google Calendar" button
- NextAuth redirects to Google OAuth consent screen
- User authorizes the application
- Google redirects back with authorization code
- NextAuth exchanges code for access token and refresh token
- Tokens are stored in the database (Account table)
Token Management
- Access tokens are short-lived (typically 1 hour)
- Refresh tokens are long-lived and used to obtain new access tokens
- The system automatically refreshes tokens when they expire
- Tokens are encrypted and stored securely in the database
Calendar Event Creation
When a booking is made:
- System retrieves user's Google access token
- Creates a calendar event using Google Calendar API
- Adds attendees (guest email)
- Generates a Google Meet link automatically
- Stores event ID and Meet link in booking record
- Sends calendar invite to guest
Required Scopes
openid: User identity verificationhttps://www.googleapis.com/auth/userinfo.email: Access to user's email addresshttps://www.googleapis.com/auth/userinfo.profile: Access to basic profile informationhttps://www.googleapis.com/auth/calendar.events: Create and manage events
Security Considerations
- Never commit Google OAuth credentials to version control
- Use environment variables for sensitive data
- Keep
.envfile in.gitignore - Use different OAuth clients for development and production
- Regularly rotate your OAuth client secrets
- Request only the minimum required scopes
Troubleshooting
"Google Calendar not connected" error
- Ensure you've connected your Google account in Settings
- Check that tokens are stored in the database
- Verify environment variables are set correctly
Token refresh failures
- Check that refresh token is present in Account table
- Verify OAuth client credentials are valid
- Ensure user hasn't revoked access in Google account settings
Calendar event creation fails
- Verify Google Calendar API is enabled
- Check that required scopes are granted
- Ensure access token is valid and not expired
Testing
To test Google Calendar integration:
- Connect your Google account in Settings
- Create a test event type
- Book a test meeting
- Check your Google Calendar for the created event
- Verify Google Meet link is generated
Production Deployment
Before deploying to production:
- Create a new OAuth client in Google Cloud Console
- Add production redirect URI
- Update environment variables in production
- Complete OAuth consent screen verification (optional but recommended)
- Test the full booking flow in production