My-Weekly-ToDo-List/.planning/phases/03-calendar-integration/03-04-PLAN.md
mARTin c82572935c feat: dark mode color adjustment, multi-source quotes, UI text wrapping, and versioning rules
- Add dark mode color adjustment helper for category colors
- Support multiple motivational quote source URLs
- Fix text wrapping for tasks/events to prevent horizontal overflow
- Improve someday list item layout for long text
- Add CLAUDE.md with semantic versioning and git workflow rules
- Update test/doc URLs and planning docs

v1.1.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 23:33:25 +01:00

6.4 KiB

phase plan type wave depends_on files_modified autonomous gap_closure must_haves
03-calendar-integration 04 execute 1
src/app/api/calendar/google/oauth/route.ts
src/app/api/calendar/apple/oauth/route.ts
src/lib/google-calendar.ts
src/lib/apple-calendar.ts
src/lib/calendar-sync.ts
prisma/schema.prisma
true true
truths artifacts key_links
User can connect their Google Calendar account
User can connect their Apple Calendar account
User can view calendar events alongside tasks in weekly view
User can manage calendar connection settings from the application
User's tasks and calendar events are synchronized bidirectionally
path provides
src/app/api/calendar/google/oauth/route.ts Real Google API token exchange implementation
path provides
src/app/api/calendar/apple/oauth/route.ts Real Apple API token exchange implementation
path provides
src/lib/google-calendar.ts Real Google Calendar API integration
path provides
src/lib/apple-calendar.ts Real Apple Calendar API integration
path provides
src/lib/calendar-sync.ts Complete bidirectional sync implementation
path provides
prisma/schema.prisma CalendarConnection model with all necessary fields
from to via pattern
src/app/api/calendar/google/oauth/route.ts src/lib/google-calendar.ts token exchange via initializeOAuth function initializeOAuth.*google
from to via pattern
src/app/api/calendar/apple/oauth/route.ts src/lib/apple-calendar.ts token exchange via initializeOAuth function initializeOAuth.*apple
from to via pattern
src/lib/calendar-sync.ts prisma/calendarConnection database operations for storing tokens prisma.calendarConnection

Gap Closure: Calendar OAuth Implementation

Objective

Fix incomplete Google and Apple Calendar OAuth implementations to enable real calendar account connections.

Purpose

Enable users to securely connect their Google and Apple Calendar accounts through proper OAuth flows.

Output

Functional OAuth endpoints that exchange authorization codes for real tokens and store them securely in the database.

Tasks

Fix Google OAuth Callback with Real Token Exchange src/app/api/calendar/google/oauth/route.ts Replace the current placeholder implementation with a real token exchange:
1. Remove hardcoded mock tokens from the implementation
2. Implement real API call to exchange the authorization code for access and refresh tokens using the Google OAuth2 API
3. Store valid tokens in the database using Prisma ORM instead of console logging
4. Add proper error handling for token exchange failures with informative messages
5. Implement token validation to ensure they're valid before saving

The implementation should:
- Call the Google OAuth2 token endpoint with the authorization code
- Handle successful token exchange results
- Handle and log token exchange errors appropriately  
- Store the tokens in the CalendarConnection database record
Run `curl -X GET "http://localhost:3001/api/calendar/google/oauth?code=valid_code"` and verify tokens are stored in database instead of just console logged Google OAuth callback endpoint exchanges real tokens and stores them in database Fix Apple OAuth Callback with Real Token Exchange src/app/api/calendar/apple/oauth/route.ts Replace the current placeholder implementation with a real token exchange:
1. Remove hardcoded mock tokens from the implementation
2. Implement real API call to exchange the authorization code for access and refresh tokens using Apple's OAuth2 API
3. Store valid tokens in the database using Prisma ORM instead of console logging
4. Add proper error handling for token exchange failures with informative messages
5. Implement token validation to ensure they're valid before saving

The implementation should:
- Make a POST request to Apple's token endpoint with code, client_id, client_secret, and redirect_uri
- Handle successful token exchange results
- Handle and log token exchange errors appropriately
- Store the tokens in the CalendarConnection database record
Run `curl -X GET "http://localhost:3001/api/calendar/apple/oauth?code=valid_code"` and verify tokens are stored in database instead of just console logged Apple OAuth callback endpoint exchanges real tokens and stores them in database Implement Database Storage for OAuth Tokens prisma/schema.prisma Update the CalendarConnection model to include necessary fields for storing OAuth tokens properly:
1. Ensure the model has all required fields for storing tokens (access_token, refresh_token, expires_at)
2. Add proper database constraints and validations
3. Ensure relationships with User model are properly defined

Currently, we have proper fields, but we need to make sure:
- The model properly supports both Google and Apple token formats
- Fields are properly indexed for performance
- The relationship with User is correctly defined
Check that prisma/schema.prisma defines CalendarConnection model with userId, provider, accessToken, refreshToken, expiresAt fields CalendarConnection model properly defined with all required fields for OAuth token storage

Verification

After completing these tasks, the following checks should pass:

  • Google OAuth callback exchanges real tokens instead of using placeholders
  • Apple OAuth callback exchanges real tokens instead of using placeholders
  • OAuth tokens are stored in the database properly instead of just logged
  • All error cases have proper handling and reporting

Success Criteria

All gaps identified in the VERIFICATION.md for Google and Apple OAuth implementations are resolved:

  • OAuth endpoints use real API token exchange instead of placeholder implementations
  • OAuth tokens are securely stored in the database
  • Proper error handling for token exchange failures