Skip to content

Commit

Permalink
fix: only forward required cookie header (#1644)
Browse files Browse the repository at this point in the history
Co-authored-by: Josip Igrec <josip@igr.ec>
  • Loading branch information
juliusmarminge and Allypost authored Nov 2, 2023
1 parent 2052334 commit e6649f1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-radios-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix: only forward required cookie header
6 changes: 4 additions & 2 deletions cli/template/extras/src/app/layout/with-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "~/styles/globals.css";

import { Inter } from "next/font/google";
import { headers } from "next/headers";
import { cookies } from "next/headers";

import { TRPCReactProvider } from "~/trpc/react";

Expand All @@ -24,7 +24,9 @@ export default function RootLayout({
return (
<html lang="en">
<body className={`font-sans ${inter.variable}`}>
<TRPCReactProvider headers={headers()}>{children}</TRPCReactProvider>
<TRPCReactProvider cookies={cookies().toString()}>
{children}
</TRPCReactProvider>
</body>
</html>
);
Expand Down
6 changes: 4 additions & 2 deletions cli/template/extras/src/app/layout/with-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "~/styles/globals.css";

import { Inter } from "next/font/google";
import { headers } from "next/headers";
import { cookies } from "next/headers";

import { TRPCReactProvider } from "~/trpc/react";

Expand All @@ -23,7 +23,9 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<TRPCReactProvider headers={headers()}>{children}</TRPCReactProvider>
<TRPCReactProvider cookies={cookies().toString()}>
{children}
</TRPCReactProvider>
</body>
</html>
);
Expand Down
9 changes: 5 additions & 4 deletions cli/template/extras/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const api = createTRPCReact<AppRouter>();

export function TRPCReactProvider(props: {
children: React.ReactNode;
headers: Headers;
cookies: string;
}) {
const [queryClient] = useState(() => new QueryClient());

Expand All @@ -28,9 +28,10 @@ export function TRPCReactProvider(props: {
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
const heads = new Map(props.headers);
heads.set("x-trpc-source", "react");
return Object.fromEntries(heads);
return {
cookie: props.cookies,
"x-trpc-source": "react",
};
},
}),
],
Expand Down
9 changes: 5 additions & 4 deletions cli/template/extras/src/trpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
loggerLink,
unstable_httpBatchStreamLink,
} from "@trpc/client";
import { headers } from "next/headers";
import { cookies } from "next/headers";

import { type AppRouter } from "~/server/api/root";
import { getUrl, transformer } from "./shared";
Expand All @@ -19,9 +19,10 @@ export const api = createTRPCProxyClient<AppRouter>({
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
const heads = new Map(headers());
heads.set("x-trpc-source", "rsc");
return Object.fromEntries(heads);
return {
cookie: cookies().toString(),
"x-trpc-source": "rsc",
};
},
}),
],
Expand Down

0 comments on commit e6649f1

Please sign in to comment.