"use client" import { useQuery } from "@tanstack/react-query" import { createSupabaseBrowserClient } from "@/lib/supabase/client" import { queryKeys } from "./query-keys" import type { UserProfile } from "@/lib/types/user-profile" export function useUserProfile() { const supabaseClient = createSupabaseBrowserClient() return useQuery({ queryKey: queryKeys.userProfile.all, queryFn: async () => { const { data: { user }, } = await supabaseClient.auth.getUser() if (!user) throw new Error("not authenticated") const { data, error } = await supabaseClient .from("user_profiles") .select( "id, display_name, tier, feed_count, folder_count, muted_keyword_count, custom_feed_count, stripe_subscription_status, stripe_current_period_end" ) .eq("id", user.id) .single() if (error) throw error const profile: UserProfile = { identifier: data.id, email: user.email ?? null, displayName: data.display_name, tier: data.tier, feedCount: data.feed_count, folderCount: data.folder_count, mutedKeywordCount: data.muted_keyword_count, customFeedCount: data.custom_feed_count, stripeSubscriptionStatus: data.stripe_subscription_status, stripeCurrentPeriodEnd: data.stripe_current_period_end, } return profile }, }) }