GrantForge Bot
Deploy to Hugging Face
afd56bc
import { useQuery } from '@tanstack/react-query';
import { useAuth } from '@clerk/clerk-react';
export interface MeData {
clerk_id: string;
tier: 'free' | 'pro' | 'business';
wizard_iterations_today: number;
tokens_used_month: number;
limits: {
max_wizard_iterations: number;
max_tokens_monthly: number;
};
}
const API_URL = import.meta.env.VITE_API_URL ?? '';
export function useMe() {
const { getToken } = useAuth();
return useQuery<MeData>({
queryKey: ['me'],
queryFn: async () => {
const token = await getToken();
const res = await fetch(`${API_URL}/api/me`, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
if (!res.ok) throw new Error('Failed to fetch /api/me');
return res.json();
},
staleTime: 30_000,
retry: false,
});
}