Spaces:
Running
Running
Download apps/admin/src/lib/trpc.ts from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/admin/src/lib/trpc.ts
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/admin/src/lib/trpc.ts
-
curl -L -o trpc.ts https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/admin/src/lib/trpc.ts
1.63 kB
| import { createTRPCReact, httpBatchLink } from "@trpc/react-query"; | |
| import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server"; | |
| import type { AppRouter } from "@micprotocol/api"; | |
| export const trpc = createTRPCReact<AppRouter>(); | |
| export function getTrpcClient() { | |
| return trpc.createClient({ | |
| links: [ | |
| httpBatchLink({ | |
| url: "/trpc", | |
| headers() { | |
| const headers: Record<string, string> = {}; | |
| // Dev-only: bypass auth via x-user-id header when DEV_AUTH_BYPASS_ENABLED=true | |
| if (process.env.NODE_ENV !== "production") { | |
| const devUserId = | |
| typeof localStorage !== "undefined" | |
| ? localStorage.getItem("micprotocol_admin_user_id") | |
| : null; | |
| if (devUserId) headers["x-user-id"] = devUserId; | |
| const workspaceId = | |
| typeof localStorage !== "undefined" | |
| ? localStorage.getItem("micprotocol_admin_workspace_id") | |
| : null; | |
| if (workspaceId) headers["x-workspace-id"] = workspaceId; | |
| } | |
| if (typeof document !== "undefined") { | |
| const match = document.cookie | |
| .split("; ") | |
| .find((c) => c.startsWith("csrf-token=")); | |
| if (match) headers["x-csrf-token"] = match.split("=")[1]; | |
| } | |
| return headers; | |
| }, | |
| fetch(url, options) { | |
| return fetch(url, { ...options, credentials: "include" }); | |
| }, | |
| }), | |
| ], | |
| }); | |
| } | |
| export type RouterInputs = inferRouterInputs<AppRouter>; | |
| export type RouterOutputs = inferRouterOutputs<AppRouter>; | |