-
Notifications
You must be signed in to change notification settings - Fork 145
feat(auth): refactor frontend auth helpers and supabase client #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { authenticatedFetch } from "../auth-helpers"; | ||
|
|
||
| const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000"; | ||
|
|
||
| export interface CollaborationIdea { | ||
| title: string; | ||
| description: string; | ||
| collaboration_type: string; | ||
| why_it_works: string; | ||
| } | ||
|
|
||
| export interface CollaborationIdeasResponse { | ||
| ideas: CollaborationIdea[]; | ||
| } | ||
|
|
||
| /** | ||
| * Generate collaboration ideas between the current creator and a target creator | ||
| */ | ||
| export async function generateCollaborationIdeas( | ||
| targetCreatorId: string | ||
| ): Promise<CollaborationIdeasResponse> { | ||
| const url = `${API_BASE_URL}/collaborations/generate-ideas`; | ||
| const response = await authenticatedFetch(url, { | ||
| method: "POST", | ||
| body: JSON.stringify({ target_creator_id: targetCreatorId }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json().catch(() => ({})); | ||
| throw new Error( | ||
| errorData.detail || `Failed to generate collaboration ideas: ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
||
| export interface CreatorRecommendationForIdea { | ||
| creator_id: string; | ||
| display_name: string; | ||
| profile_picture_url: string | null; | ||
| primary_niche: string; | ||
| match_score: number; | ||
| reasoning: string; | ||
| } | ||
|
|
||
| export interface RecommendCreatorResponse { | ||
| recommended_creator: CreatorRecommendationForIdea; | ||
| alternatives: CreatorRecommendationForIdea[]; | ||
| } | ||
|
|
||
| /** | ||
| * Recommend the best creator from a list of candidates for a collaboration idea | ||
| */ | ||
| export async function recommendCreatorForIdea( | ||
| collaborationIdea: string, | ||
| candidateCreatorIds: string[] | ||
| ): Promise<RecommendCreatorResponse> { | ||
| const url = `${API_BASE_URL}/collaborations/recommend-creator`; | ||
| const response = await authenticatedFetch(url, { | ||
| method: "POST", | ||
| body: JSON.stringify({ | ||
| collaboration_idea: collaborationIdea, | ||
| candidate_creator_ids: candidateCreatorIds, | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json().catch(() => ({})); | ||
| throw new Error( | ||
| errorData.detail || `Failed to get recommendation: ${response.statusText}` | ||
| ); | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| import { authenticatedFetch } from "../auth-helpers"; | ||
|
|
||
| const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000"; | ||
|
|
||
| export interface CreatorBasic { | ||
| id: string; | ||
| display_name: string; | ||
| tagline: string | null; | ||
| bio: string | null; | ||
| profile_picture_url: string | null; | ||
| primary_niche: string; | ||
| secondary_niches: string[] | null; | ||
| total_followers: number; | ||
| engagement_rate: number | null; | ||
| is_verified_creator: boolean; | ||
| profile_completion_percentage: number; | ||
| } | ||
|
|
||
| export interface CreatorFull extends CreatorBasic { | ||
| user_id: string; | ||
| cover_image_url: string | null; | ||
| website_url: string | null; | ||
| youtube_url: string | null; | ||
| youtube_handle: string | null; | ||
| youtube_subscribers: number | null; | ||
| instagram_url: string | null; | ||
| instagram_handle: string | null; | ||
| instagram_followers: number | null; | ||
| tiktok_url: string | null; | ||
| tiktok_handle: string | null; | ||
| tiktok_followers: number | null; | ||
| twitter_url: string | null; | ||
| twitter_handle: string | null; | ||
| twitter_followers: number | null; | ||
| twitch_url: string | null; | ||
| twitch_handle: string | null; | ||
| twitch_followers: number | null; | ||
| linkedin_url: string | null; | ||
| facebook_url: string | null; | ||
| content_types: string[] | null; | ||
| content_language: string[] | null; | ||
| total_reach: number | null; | ||
| average_views: number | null; | ||
| audience_age_primary: string | null; | ||
| audience_gender_split: Record<string, any> | null; | ||
| audience_locations: Record<string, any> | null; | ||
| audience_interests: string[] | null; | ||
| average_engagement_per_post: number | null; | ||
| posting_frequency: string | null; | ||
| best_performing_content_type: string | null; | ||
| years_of_experience: number | null; | ||
| content_creation_full_time: boolean; | ||
| team_size: number; | ||
| equipment_quality: string | null; | ||
| editing_software: string[] | null; | ||
| collaboration_types: string[] | null; | ||
| preferred_brands_style: string[] | null; | ||
| rate_per_post: number | null; | ||
| rate_per_video: number | null; | ||
| rate_per_story: number | null; | ||
| rate_per_reel: number | null; | ||
| rate_negotiable: boolean; | ||
| accepts_product_only_deals: boolean; | ||
| minimum_deal_value: number | null; | ||
| preferred_payment_terms: string | null; | ||
| portfolio_links: string[] | null; | ||
| past_brand_collaborations: string[] | null; | ||
| case_study_links: string[] | null; | ||
| media_kit_url: string | null; | ||
| created_at: string | null; | ||
| last_active_at: string | null; | ||
| } | ||
|
|
||
| export interface ListCreatorsParams { | ||
| search?: string; | ||
| niche?: string; | ||
| limit?: number; | ||
| offset?: number; | ||
| } | ||
|
|
||
| /** | ||
| * List all creators with optional search and filters | ||
| */ | ||
| export async function listCreators( | ||
| params: ListCreatorsParams = {} | ||
| ): Promise<CreatorBasic[]> { | ||
| const queryParams = new URLSearchParams(); | ||
| if (params.search) queryParams.append("search", params.search); | ||
| if (params.niche) queryParams.append("niche", params.niche); | ||
| if (params.limit) queryParams.append("limit", params.limit.toString()); | ||
| if (params.offset) queryParams.append("offset", params.offset.toString()); | ||
|
|
||
| const url = `${API_BASE_URL}/creators?${queryParams.toString()}`; | ||
| const response = await authenticatedFetch(url); | ||
|
|
||
| if (!response.ok) { | ||
| // Try to get error details from response | ||
| let errorMessage = `Failed to fetch creators: ${response.statusText}`; | ||
| try { | ||
| const errorData = await response.json(); | ||
| if (errorData.detail) { | ||
| errorMessage = errorData.detail; | ||
| } | ||
| } catch { | ||
| // If response is not JSON, use status text | ||
| } | ||
|
|
||
| const error = new Error(errorMessage); | ||
| (error as any).status = response.status; | ||
| throw error; | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
||
| /** | ||
| * Get full details of a specific creator | ||
| */ | ||
| export async function getCreatorDetails(creatorId: string): Promise<CreatorFull> { | ||
| const url = `${API_BASE_URL}/creators/${creatorId}`; | ||
| const response = await authenticatedFetch(url); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch creator details: ${response.statusText}`); | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
||
| export interface CreatorRecommendation { | ||
| id: string; | ||
| display_name: string; | ||
| profile_picture_url: string | null; | ||
| primary_niche: string | null; | ||
| total_followers: number | null; | ||
| engagement_rate: number | null; | ||
| top_platforms?: string[] | null; | ||
| match_score: number; | ||
| reason: string; | ||
| } | ||
|
|
||
| export async function getCreatorRecommendations(limit = 4): Promise<CreatorRecommendation[]> { | ||
| const url = `${API_BASE_URL}/creators/recommendations?limit=${limit}`; | ||
| const response = await authenticatedFetch(url); | ||
|
|
||
| if (!response.ok) { | ||
| const errText = await response.text().catch(() => ""); | ||
| throw new Error(`Failed to fetch recommendations: ${response.status} ${errText}`); | ||
| } | ||
| return response.json(); | ||
| } | ||
|
|
||
| /** | ||
| * Get list of all unique niches | ||
| */ | ||
| export async function listNiches(): Promise<string[]> { | ||
| const url = `${API_BASE_URL}/creators/niches/list`; | ||
| const response = await authenticatedFetch(url); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch niches: ${response.statusText}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data.niches || []; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.