From f22405b064c944bd23fac654f3535e2f03bd27a3 Mon Sep 17 00:00:00 2001 From: Aleksei Gurianov Date: Mon, 19 Aug 2024 23:46:10 +0300 Subject: [PATCH] fix issue with prefetch protected procedure in auth templates Fixes #1961 Add condition to prefetch `getLatest` only if the user is authenticated. --- .changeset/lucky-parents-invent.md | 5 +++++ cli/template/extras/src/app/page/with-auth-trpc-tw.tsx | 4 +++- cli/template/extras/src/app/page/with-auth-trpc.tsx | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/lucky-parents-invent.md diff --git a/.changeset/lucky-parents-invent.md b/.changeset/lucky-parents-invent.md new file mode 100644 index 0000000000..99e678b28e --- /dev/null +++ b/.changeset/lucky-parents-invent.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": patch +--- + +fix issue with prefetch protected procedure in auth templates diff --git a/cli/template/extras/src/app/page/with-auth-trpc-tw.tsx b/cli/template/extras/src/app/page/with-auth-trpc-tw.tsx index 49c9bbbe20..1d462b4441 100644 --- a/cli/template/extras/src/app/page/with-auth-trpc-tw.tsx +++ b/cli/template/extras/src/app/page/with-auth-trpc-tw.tsx @@ -8,7 +8,9 @@ export default async function Home() { const hello = await api.post.hello({ text: "from tRPC" }); const session = await getServerAuthSession(); - void api.post.getLatest.prefetch(); + if (session?.user) { + void api.post.getLatest.prefetch(); + } return ( diff --git a/cli/template/extras/src/app/page/with-auth-trpc.tsx b/cli/template/extras/src/app/page/with-auth-trpc.tsx index cfeed2f5b5..74cac168f9 100644 --- a/cli/template/extras/src/app/page/with-auth-trpc.tsx +++ b/cli/template/extras/src/app/page/with-auth-trpc.tsx @@ -9,7 +9,9 @@ export default async function Home() { const hello = await api.post.hello({ text: "from tRPC" }); const session = await getServerAuthSession(); - void api.post.getLatest.prefetch(); + if (session?.user) { + void api.post.getLatest.prefetch(); + } return (