API and data
For Admin panel only projects, the login is /, the home page is /dashboard, and other panel pages omit the /admin prefix. Components use @/components and @/components/ui. API endpoints such as /api/admin/users/export keep their paths. Examples below use the combined public website + admin panel layout; generated standalone guides use the app’s actual paths.
Use tRPC for typed application APIs and TanStack Query to fetch, cache, and refresh data in the browser.
This guide applies to Public website + admin panel and Admin panel only projects.
The generated project already includes both providers, a working health query, and protected account/admin procedures. No extra installation is needed.
Read data in client components
Create a Client Component that uses the existing health query:
// src/components/api-status.tsx
"use client";
import { useQuery } from "@tanstack/react-query";
import { Skeleton } from "@/components/ui/skeleton";
import { useTRPC } from "@/trpc/client";
export function ApiStatus() {
const trpc = useTRPC();
const query = useQuery(trpc.health.queryOptions());
return (
<section aria-labelledby="api-status-title">
<h2 id="api-status-title">API status</h2>
{query.data ? (
<output>{query.data.status}</output>
) : query.isError ? (
<p role="alert">API status is unavailable.</p>
) : (
<Skeleton className="h-5 w-16" />
)}
</section>
);
}
Render ApiStatus from a page. Its heading appears immediately; only the unresolved status has a skeleton. Existing data stays visible during a background refresh.
Included procedures
| Procedure | Access | Result |
|---|---|---|
health |
Public | Status and timestamp |
auth.me |
Signed-in, non-banned user | Safe profile fields |
admin.status |
Administrator | Authorization status |
admin.users |
Administrator | Paginated, filtered users |
admin.user |
Administrator | One user’s display fields |
SuperJSON preserves dates through HTTP and server hydration, so the health timestamp remains a Date.
In this section
- Protected procedures: Add validated API operations and choose an authorization level.
- Server rendering: Read on the server or prefetch a query for client hydration.
- Query cache and loading: Refresh data, handle identity changes and scope loading states.
- Admin tables and CSV: Reuse table controls, URL filters, pagination and exports.