Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no-cookies-for-cc #1723

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-donuts-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix: don't pass cookies to CC
5 changes: 1 addition & 4 deletions cli/template/extras/src/app/layout/with-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "~/styles/globals.css";

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

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

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

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

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

Expand All @@ -23,9 +22,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<TRPCReactProvider cookies={cookies().toString()}>
{children}
</TRPCReactProvider>
<TRPCReactProvider>{children}</TRPCReactProvider>
</body>
</html>
);
Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/app/page/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { unstable_noStore as noStore } from "next/cache";
import Link from "next/link";

import { CreatePost } from "~/app/_components/create-post";
import { getServerAuthSession } from "~/server/auth";
import { api } from "~/trpc/server";

export default async function Home() {
noStore();
const hello = await api.post.hello.query({ text: "from tRPC" });
const session = await getServerAuthSession();

Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/app/page/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { unstable_noStore as noStore } from "next/cache";
import Link from "next/link";

import { CreatePost } from "~/app/_components/create-post";
Expand All @@ -6,6 +7,7 @@ import { api } from "~/trpc/server";
import styles from "./index.module.css";

export default async function Home() {
noStore();
const hello = await api.post.hello.query({ text: "from tRPC" });
const session = await getServerAuthSession();

Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/app/page/with-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { unstable_noStore as noStore } from "next/cache";
import Link from "next/link";

import { CreatePost } from "~/app/_components/create-post";
import { api } from "~/trpc/server";

export default async function Home() {
noStore();
const hello = await api.post.hello.query({ text: "from tRPC" });

return (
Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/app/page/with-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { unstable_noStore as noStore } from "next/cache";
import Link from "next/link";

import { CreatePost } from "~/app/_components/create-post";
import { api } from "~/trpc/server";
import styles from "./index.module.css";

export default async function Home() {
noStore();
const hello = await api.post.hello.query({ text: "from tRPC" });

return (
Expand Down
11 changes: 1 addition & 10 deletions cli/template/extras/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { getUrl, transformer } from "./shared";

export const api = createTRPCReact<AppRouter>();

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

const [trpcClient] = useState(() =>
Expand All @@ -27,12 +24,6 @@ export function TRPCReactProvider(props: {
}),
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
return {
cookie: props.cookies,
"x-trpc-source": "react",
};
},
}),
],
})
Expand Down
10 changes: 5 additions & 5 deletions cli/template/extras/src/trpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { callProcedure } from "@trpc/server";
import { observable } from "@trpc/server/observable";
import { type TRPCErrorResponse } from "@trpc/server/rpc";
import { cookies } from "next/headers";
import { headers } from "next/headers";
import { cache } from "react";

import { appRouter, type AppRouter } from "~/server/api/root";
Expand All @@ -20,11 +20,11 @@ import { transformer } from "./shared";
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(() => {
const heads = new Headers(headers());
heads.set("x-trpc-source", "rsc");

return createTRPCContext({
headers: new Headers({
cookie: cookies().toString(),
"x-trpc-source": "rsc",
}),
headers: heads,
});
});

Expand Down