Skip to content

Add Polar payments, WorkOS authentication, and Convex database integrations#4

Merged
developersdigest merged 11 commits intomainfrom
devin/1751197861-add-polar-workos-convex-pages
Jun 29, 2025
Merged

Add Polar payments, WorkOS authentication, and Convex database integrations#4
developersdigest merged 11 commits intomainfrom
devin/1751197861-add-polar-workos-convex-pages

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Jun 29, 2025

Add Polar Payments, WorkOS Authentication, and Convex Database Integration

Summary

This PR implements comprehensive integrations for the Fireplexity AI search engine:

  • 🔐 WorkOS Authentication: User authentication system with sign-in/sign-out flows
  • 💳 Polar Payments: Subscription system with Free ($0/month, 10 searches/day) and Pro ($9.99/month, unlimited) tiers
  • 📊 Convex Database: User management, search history persistence, and subscription tracking
  • 🎨 Landing Page: Complete marketing site with pricing, features, and call-to-action sections
  • ⚙️ API Routes: Authentication endpoints, checkout flow, and webhook handlers

⚠️ IMPORTANT: Due to persistent WorkOS configuration issues during development, authentication is currently disabled with mock user data in place for local development. This requires immediate attention before production deployment.

Review & Testing Checklist for Human

  • 🚨 CRITICAL: Remove hardcoded mock user data from /api/auth/me and /api/checkout routes and restore proper WorkOS authentication
  • 🚨 CRITICAL: Test WorkOS authentication flow end-to-end (sign-in, sign-out, session management)
  • 🔍 HIGH PRIORITY: Test Polar payment integration completely - create checkout sessions, process payments, handle webhooks
  • 🔧 HIGH PRIORITY: Verify environment variables load properly in production environment (WorkOS cookie password errors occurred locally)
  • ✅ MEDIUM: Test database operations with concurrent users and subscription limit enforcement

Recommended Test Plan:

  1. Configure WorkOS properly and re-enable authentication middleware
  2. Test complete user journey: sign-up → free tier usage → upgrade to pro → unlimited searches
  3. Verify webhook handling for subscription changes
  4. Test search history persistence across user sessions

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    subgraph "Frontend"
        LP["app/page.tsx<br/>Landing Page"]:::major-edit
        DASH["app/dashboard/page.tsx<br/>Dashboard"]:::major-edit
        SEARCH["app/search/page.tsx<br/>Search Interface"]:::major-edit
    end
    
    subgraph "Authentication"
        MW["middleware.ts<br/>Auth Middleware"]:::major-edit
        AUTH_ME["app/api/auth/me/route.ts<br/>User Session"]:::major-edit
        PROVIDERS["components/providers.tsx<br/>Auth Provider"]:::major-edit
    end
    
    subgraph "Payments"
        CHECKOUT["app/api/checkout/route.ts<br/>Polar Checkout"]:::major-edit
        WEBHOOK["app/api/webhooks/polar/route.ts<br/>Subscription Events"]:::major-edit
    end
    
    subgraph "Database"
        USERS["convex/users.ts<br/>User Management"]:::major-edit
        SEARCHES["convex/searches.ts<br/>Search History"]:::major-edit
        SCHEMA["convex/schema.ts<br/>Database Schema"]:::major-edit
    end
    
    subgraph "Configuration"
        ENV[".env.local<br/>Environment Variables"]:::minor-edit
        LAYOUT["app/layout.tsx<br/>Root Layout"]:::minor-edit
    end

    LP --> AUTH_ME
    DASH --> USERS
    SEARCH --> SEARCHES
    MW --> AUTH_ME
    CHECKOUT --> WEBHOOK
    PROVIDERS --> USERS
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit
        L3["Context/No Edit"]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB  
classDef context fill:#FFFFFF
Loading

Notes

  • Session Reference: This work was completed in Devin session https://app.devin.ai/sessions/d68a50c188744f1abe1182a033c6913b
  • Requested by: @developersdigest (developers.digest.ai@gmail.com)
  • Authentication Status: Currently using mock data due to WorkOS configuration issues - requires immediate fix before production
  • Payment Integration: Polar product created successfully but API compatibility needs verification
  • Database Testing: Convex integration tested with concurrent operations and retry mechanisms
  • Local Development: Both npx convex dev and npm run dev required to run the application

Screenshots:
Landing Page
Polar Checkout

- Set up Convex database with user profiles, search history, and subscriptions
- Implement WorkOS authentication with middleware and auth routes
- Add Polar payment integration with checkout and webhook handlers
- Create landing page for unauthenticated users with pricing tiers
- Create dashboard page for authenticated users with usage tracking
- Move search functionality to authenticated route with usage limits
- Add proper providers and layout structure for auth and database
- Implement subscription tiers: Free (10 searches/day) and Pro (unlimited)
- Add server-side API key management for Firecrawl and OpenAI

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 10 commits June 29, 2025 12:48
- Add retry logic with exponential backoff to handle OptimisticConcurrencyControlFailure
- Prevents data corruption when multiple users search simultaneously
- Tested with 5 concurrent operations - all succeed correctly
- Critical fix discovered during comprehensive multi-user testing

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
- Handle subscription.created, subscription.updated, and subscription.canceled events
- Process webhook data and log subscription changes
- Return proper HTTP responses for webhook validation
- Integrate with existing middleware configuration

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
- Replace problematic authkitMiddleware with simple pass-through middleware
- Resolves persistent cookie password validation errors
- Allows core application and Convex integration to work properly
- Application now loads successfully at localhost:3000

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
- Remove WorkOS withAuth dependency from /api/auth/me route
- Replace with mock user data for local development testing
- Resolves 'withAuth not covered by middleware' errors

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
- Remove WorkOS getUser dependency from /api/checkout route
- Replace with mock user data for local development testing
- Resolves remaining 'withAuth not covered by middleware' errors
- All WorkOS authentication calls now removed for local dev

Co-Authored-By: Developers Digest <softwaredevelopmentvideos2023@gmail.com>
- Update middleware to use standard authkit configuration
- Fix signin/signout routes to use proper Next.js patterns
- Convert Link components to anchor tags for OAuth flow
- Add automatic redirect to dashboard for authenticated users
- Fix environment variables (use NEXT_PUBLIC_WORKOS_REDIRECT_URI)
- Add error logging and debugging routes

Co-Authored-By: Claude <noreply@anthropic.com>
- Implement search usage tracking with daily limits
- Add incrementSearchCount and canUserSearch to track user searches
- Fix URL parsing error in chat interface with proper error handling
- Configure WorkOS middleware with homepage URL requirement
- Update Polar configuration to use sandbox environment
- Add proper error handling for expired Polar API tokens
- Track usage stats in dashboard showing searches used today
- Prevent users from exceeding daily search limits (10 for free tier)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add try-catch block for second URL parsing occurrence
- Return 'Unknown source' when URL is invalid
- Prevents runtime errors when search results have malformed URLs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Switch Pro tier from unlimited to 500 searches per month
- Add credit-based tracking system for Pro users
- Implement monthly credit reset mechanism
- Add credits display in navigation bar
- Update dashboard to show monthly credits for Pro users
- Add meter reporting to Polar for usage tracking
- Create API endpoints for usage reporting and balance checking
- Update schema to support both daily (free) and monthly (pro) tracking

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix signOut route to redirect to home page
- Add Suspense boundary to dashboard page for useSearchParams
- Install missing next-themes dependency
- Remove debug/test API routes that expose sensitive info
- Fix TypeScript type errors with search limits
- Update meter API endpoints to use placeholders (not available in sandbox)
- Ensure build completes successfully

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@developersdigest developersdigest merged commit 71ebc1d into main Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant