tRPCttRPC
Powered by
dionD
tRPC•3y ago
dion

forwarding headers in solidjs

I have a setup with solidstart, and im trying to forward the client headeres to ttrpc.
Here's my setup:
// This is not forwarding the client headers.
export const trpc = createTRPCProxyClient<IAppRouter>({
  links: [
    httpBatchLink({
      url: `${getBaseUrl()}/api/trpc`,
      headers() {
        // how to forward client headers?
        const heads = new Map(); // <-- specifically this part
        return Object.fromEntries(heads);
      },
    }),
  ],
});
// This is not forwarding the client headers.
export const trpc = createTRPCProxyClient<IAppRouter>({
  links: [
    httpBatchLink({
      url: `${getBaseUrl()}/api/trpc`,
      headers() {
        // how to forward client headers?
        const heads = new Map(); // <-- specifically this part
        return Object.fromEntries(heads);
      },
    }),
  ],
});

This is how i'm calling the
trpc
trpc
client from my component:
export const routeData = () => {
  return createServerData$(async () => {
    const organizations =
      await trpc.organization.getOrganizationsByUser.query();
    return organizations;
  });
};

const Page: VoidComponent = () => {
  const organizations = useRouteData<typeof routeData>();
  return (
    <div>
      Organizations
    </div>
  );
};

export default Page;
export const routeData = () => {
  return createServerData$(async () => {
    const organizations =
      await trpc.organization.getOrganizationsByUser.query();
    return organizations;
  });
};

const Page: VoidComponent = () => {
  const organizations = useRouteData<typeof routeData>();
  return (
    <div>
      Organizations
    </div>
  );
};

export default Page;

Is there a way to forward the headers received by the handler?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

trpc+solidjs
sebSseb / ❓-help
10mo ago
Auth Headers in Singleton Pattern
Sica / BenSSica / Ben / ❓-help
11mo ago