refactor: replace useQuery with useAuthQuery for improved authentication handling

- Updated multiple components to utilize useAuthQuery instead of useQuery for fetching user-related data, enhancing authentication management.
- Adjusted balance and subscription queries across various components including InitUser, ManageSubscription, PricingCards, CreditDisplay, and others to ensure consistent authentication checks.
- Improved overall code maintainability by centralizing authentication logic in the new hook.
This commit is contained in:
Matthias
2026-03-27 18:35:12 +01:00
parent 2f89465e82
commit 6e38e2d270
9 changed files with 48 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
"use client";
import { useEffect } from "react";
import { useQuery } from "convex/react";
import { useAuthQuery } from "@/hooks/use-auth-query";
import { CreditCard } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
@@ -43,9 +43,9 @@ const LOW_CREDITS_THRESHOLD = 20;
export function CreditOverview() {
const router = useRouter();
const balance = useQuery(api.credits.getBalance);
const subscription = useQuery(api.credits.getSubscription);
const usageStats = useQuery(api.credits.getUsageStats);
const balance = useAuthQuery(api.credits.getBalance);
const subscription = useAuthQuery(api.credits.getSubscription);
const usageStats = useAuthQuery(api.credits.getUsageStats);
useEffect(() => {
if (balance === undefined) return;

View File

@@ -1,6 +1,6 @@
"use client";
import { useQuery } from "convex/react";
import { useAuthQuery } from "@/hooks/use-auth-query";
import { Activity, Coins } from "lucide-react";
import { Badge } from "@/components/ui/badge";
@@ -45,7 +45,7 @@ function truncatedDescription(text: string, maxLen = 40) {
// ---------------------------------------------------------------------------
export function RecentTransactions() {
const transactions = useQuery(api.credits.getRecentTransactions, {
const transactions = useAuthQuery(api.credits.getRecentTransactions, {
limit: 10,
});