Skip to content

Add per-channel YouTube OAuth connection flow#9

Merged
mhaadiabu merged 2 commits into
mainfrom
feature/per-channel-youtube-oauth
Mar 15, 2026
Merged

Add per-channel YouTube OAuth connection flow#9
mhaadiabu merged 2 commits into
mainfrom
feature/per-channel-youtube-oauth

Conversation

@mhaadiabu

@mhaadiabu mhaadiabu commented Mar 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a server-side per-channel Google OAuth flow that validates channel ownership and stores YouTube analytics connections in Convex
  • derive analytics sync snapshots and tax estimates from connected YouTube Analytics data for linked channels
  • update the channels and sign-in UI so officers start and resume analytics connections from a specific channel record

Summary by CodeRabbit

  • New Features

    • Added YouTube channel analytics connection workflow with OAuth authentication.
    • Connection status tracking with success/error notifications displayed on the influencers page.
    • Connect and Reconnect buttons for managing analytics-enabled channels.
    • Enhanced sign-in flow to redirect users to channel connection when applicable.
  • Refactor

    • Simplified settings page to guide users to the channels page for connection management.

@vercel

vercel Bot commented Mar 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
graitld Ready Ready Preview, Comment Mar 15, 2026 9:23am

@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 711bf3a1-36c8-406a-9e0a-a0cb178a45fa

📥 Commits

Reviewing files that changed from the base of the PR and between 43658aa and 61c001c.

📒 Files selected for processing (7)
  • convex/influencers.ts
  • src/app/(auth)/sign-in/page.tsx
  • src/app/(dashboard)/influencers/page.tsx
  • src/app/(dashboard)/settings/page.tsx
  • src/app/api/youtube/connect/callback/route.ts
  • src/app/api/youtube/connect/route.ts
  • src/lib/youtube-connect.ts

📝 Walkthrough

Walkthrough

This PR implements a complete YouTube OAuth2 connection and analytics integration flow. It adds backend mutations and queries for managing channel analytics connections, API routes for OAuth callback handling, frontend pages supporting channel connection flows, and utility functions for Google OAuth token exchange and YouTube Analytics data retrieval.

Changes

Cohort / File(s) Summary
Backend Analytics & Connection Management
convex/influencers.ts
Added mutation completeChannelAnalyticsConnection to persist OAuth tokens and optional analytics snapshots; query getChannelConnectionTarget to fetch channel connection details; internal helpers isConnectableBusinessChannelId and upsertAnalyticsSyncSnapshot for validation and analytics persistence.
OAuth Flow Library
src/lib/youtube-connect.ts
New module implementing Google OAuth2 flow: state creation/validation with HMAC signing, authorization URL construction, code exchange, and YouTube Analytics revenue snapshot retrieval with type-safe conversion.
OAuth API Routes
src/app/api/youtube/connect/route.ts, src/app/api/youtube/connect/callback/route.ts
Added initiation route validating channelId and redirecting to Google OAuth; callback route exchanging authorization code, fetching user/channel info, computing analytics snapshot, and persisting connection via backend mutation.
Frontend Sign-In Flow
src/app/(auth)/sign-in/page.tsx
Modified to accept connectChannelId and returnTo query parameters; on success, prioritizes YouTube connect flow with channelId before fallback to default redirect.
Frontend Influencer Channel Management
src/app/(dashboard)/influencers/page.tsx
Added URL parameter parsing for connection success/error notices; displays contextual banner; replaced static Remove action with Connect/Reconnect button (for connectable channels) and Remove action group.
Frontend Settings Page
src/app/(dashboard)/settings/page.tsx
Removed local Google OAuth connection handler; replaced connect button with Link to channels page; updated text to reflect per-channel connection workflow instead of account-level OAuth.

Sequence Diagram(s)

sequenceDiagram
    participant User as User / Browser
    participant SignIn as Sign-In Page
    participant OAuth as OAuth API Route
    participant Google as Google OAuth Server
    participant Callback as Callback Route
    participant Convex as Convex Backend
    participant YouTube as YouTube APIs

    User->>SignIn: Submit sign-in with connectChannelId
    SignIn->>SignIn: Authenticate & validate
    SignIn->>OAuth: Redirect to /api/youtube/connect?channelId=...
    OAuth->>Convex: Fetch channel connection target
    OAuth->>OAuth: Build authorization URL with state (HMAC signed)
    OAuth->>Google: Redirect to Google OAuth authorization
    Google->>User: OAuth consent screen
    User->>Google: Grant permissions
    Google->>Callback: Redirect with authorization code
    Callback->>Google: Exchange code for tokens
    Google->>Callback: Return access/refresh tokens
    Callback->>YouTube: Fetch user info & owned channel IDs
    YouTube->>Callback: Return user data & channels
    Callback->>YouTube: Fetch 30-day analytics snapshot
    YouTube->>Callback: Return analytics metrics
    Callback->>Convex: Call completeChannelAnalyticsConnection mutation
    Convex->>Convex: Persist OAuth connection & analytics sync
    Convex->>Callback: Return connectionId & synced flag
    Callback->>User: Redirect to returnTo with success flag
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 Hops of OAuth delight,
Tokens signed with HMAC might,
YouTube analytics flow,
Watch the channels now grow! 🎬✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/per-channel-youtube-oauth
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@mhaadiabu mhaadiabu merged commit f6ac26c into main Mar 15, 2026
3 of 4 checks passed
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