Files
lemonspace_app/hooks/use-auth-query.ts
Matthias bc3bbf9d69 feat: enhance canvas functionality with new asset node type and improved image handling
- Introduced a new "asset" node type in the canvas sidebar for better resource management.
- Updated image node components to support dynamic image dimensions and improved resizing logic.
- Enhanced prompt and AI image nodes to utilize reference images from asset nodes, improving integration and functionality.
- Refactored canvas utilities to accommodate new asset configurations and maintain consistent media handling.
2026-03-27 20:33:20 +01:00

28 lines
1.1 KiB
TypeScript

"use client";
import { useConvexAuth, useQuery } from "convex/react";
import type { FunctionReference, FunctionArgs, FunctionReturnType } from "convex/server";
/**
* Wrapper um `useQuery` der automatisch `"skip"` nutzt wenn der
* Convex-Auth-Token noch nicht bereit ist. Verhindert "Unauthenticated"-Fehler
* bei Queries die `requireAuth` nutzen.
* Convex-Queries sind reaktiv: Ergebnisse werden im Client-Cache gehalten und
* nur bei relevanten Datenänderungen aktualisiert (keine manuelle Polling-
* Schleife, z. B. alle 3000ms, notwendig).
*
* Nutzt nur `isAuthenticated` (nicht `isLoading`) als Guard — wenn ein
* `initialToken` vom SSR vorhanden ist, springt `isAuthenticated` sofort
* auf `true` ohne Loading-Phase, sodass Queries ohne Verzögerung feuern.
*/
export function useAuthQuery<F extends FunctionReference<"query">>(
query: F,
...args: [] | [FunctionArgs<F> | "skip"]
): FunctionReturnType<F> | undefined {
const { isAuthenticated } = useConvexAuth();
const shouldSkip = !isAuthenticated || args[0] === "skip";
return useQuery(query, shouldSkip ? "skip" : (args[0] ?? ({} as FunctionArgs<F>)));
}