feat(auth): refactor frontend auth helpers and supabase client#152
feat(auth): refactor frontend auth helpers and supabase client#152
Conversation
WalkthroughA 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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)
📝 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
✅ Checklist
Summary by CodeRabbit