Skip to content

Conversation

@Saahi30
Copy link
Collaborator

@Saahi30 Saahi30 commented Nov 10, 2025

📝 Description

This pull request refactors the frontend authentication helpers and Supabase client integration to improve authentication flow, maintainability, and code clarity. It also introduces a new API utility directory for better modularity.

🔧 Changes Made

  • Refactored auth-helpers.ts for improved authentication logic and error handling.
  • Updated supabaseClient.ts for cleaner Supabase integration.
  • Added new api directory for API utilities.

✅ Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if applicable).
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • New Features
    • Added collaboration matching: Generate partnership ideas and receive matched creator recommendations
    • Added creator discovery: Browse and search creators, with personalized recommendations and niche filtering
    • Improved authentication: Automatic token refresh for enhanced session stability and seamless experience

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

A new frontend API layer is introduced for collaborations and creators, paired with enhanced authentication token management including automatic refresh capabilities and improved error handling in auth helper functions.

Changes

Cohort / File(s) Summary
New API Modules for Features
frontend/lib/api/collaborations.ts, frontend/lib/api/creators.ts
Adds client-side API integration with interfaces (CollaborationIdea, CreatorBasic, CreatorFull, etc.) and functions (generateCollaborationIdeas, recommendCreatorForIdea, listCreators, getCreatorDetails, getCreatorRecommendations, listNiches) with robust error handling and HTTP status attachment.
Authentication & Token Management
frontend/lib/auth-helpers.ts, frontend/lib/supabaseClient.ts
Enhances token lifecycle management: supabaseClient now configures auth with auto-refresh and session detection; auth-helpers imports token utilities, adds ensureValidToken and authenticatedFetch (with 401 retry on token refresh), and refactors existing functions (getCurrentUser, getUserProfile, checkUserRole) for improved error handling and null returns instead of throws.

Sequence Diagram

sequenceDiagram
    actor Client
    participant AF as authenticatedFetch
    participant AH as auth-helpers
    participant SC as supabaseClient
    participant API as Backend API

    Client->>AF: fetch(url, options)
    AF->>AH: getToken via ensureValidToken
    AH->>SC: getAuthToken()
    SC-->>AH: token or undefined
    
    alt Token exists
        AF->>AF: append Authorization header
    else No token
        AH->>SC: refreshAuthToken()
        SC->>API: refresh_session
        API-->>SC: new token
        SC-->>AH: new token
        AF->>AF: append Authorization header
    end
    
    AF->>API: fetch with auth header
    API-->>AF: response
    
    alt 401 Unauthorized
        AF->>SC: refreshAuthToken()
        SC->>API: refresh_session
        API-->>SC: new token
        SC-->>AF: new token
        AF->>API: retry fetch with new token
        API-->>AF: response (retry result)
    end
    
    AF-->>Client: return Response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • authenticatedFetch retry logic: The 401 retry mechanism with token refresh requires careful verification of edge cases (e.g., refresh failure during retry, infinite retry prevention).
  • Token management flow: Interaction between getAuthToken, refreshAuthToken, and authenticatedFetch—verify proper error propagation and token state consistency across async operations.
  • Error handling changes in auth-helpers: Review refactored functions (getCurrentUser, checkUserRole, getUserProfile) to ensure null returns don't break existing call sites.
  • Supabase client auth configuration: Validate that auto-refresh and session detection settings align with intended behavior and don't conflict with explicit refresh calls in auth-helpers.

Possibly related PRs

Poem

🐰 Hops with glee through auth-tokens bright,
New API paths make futures light,
With refresh so swift and errors caught,
Creators dance with friends they sought!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring frontend authentication helpers and Supabase client integration, which aligns with the four modified files (auth-helpers.ts, supabaseClient.ts, creators.ts, collaborations.ts) that all relate to authentication and API utilities for the frontend.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/frontend-auth-supabase

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.

@Saahi30
Copy link
Collaborator Author

Saahi30 commented Nov 10, 2025

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75d828b and a688a45.

📒 Files selected for processing (4)
  • frontend/lib/api/collaborations.ts (1 hunks)
  • frontend/lib/api/creators.ts (1 hunks)
  • frontend/lib/auth-helpers.ts (5 hunks)
  • frontend/lib/supabaseClient.ts (1 hunks)

@Saahi30 Saahi30 merged commit c715ff4 into dev Nov 10, 2025
1 check passed
@Saahi30 Saahi30 deleted the feat/frontend-auth-supabase branch November 10, 2025 17:35
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.

2 participants